Run The Currently Open Lua File In Neovim
October 2023
The Command
You can execute an open .lau file buffer inside Neovim with the "source" command like this:
:soSome Notes
-
The
:help sourceentry lists the details of:[range]so[urce] [file]as:Runs
Excommands or Lua code (".lua" files) from [file], or current buffer if no [file]. Triggers theSourcePreautocommand. -
The command works with files that have a
.luaextension -
The command also works with non-saved buffers that are named with a
.luaextension. For example, you can do:e tmp.lau, write some code and run it with:so, then delete the buffer with:bd! -
The
:socommand is shorthand for:source. I like using the shorter version, but the longer one works the same -
The command can also be run with
%like:so %which uses the file path of the current buffer instead of the buffer itself. That means if you make changes to the file buffer without saving them you'll see different behaviour from:soand:so %until you save the file
end of line
References
I copy/pasted the entry above. There's some more links and other stuff around the entry and I've never found skimming around docs to be time wasted