Run The Currently Open Lua File In Neovim
The Command
You can execute an open .lau file buffer inside Neovim with the "source" command like this:
:so
Some Notes
-
The
:help source
entry lists the details of:[range]so[urce] [file]
as:Runs
Ex
commands or Lua code (".lua" files) from [file], or current buffer if no [file]. Triggers theSourcePre
autocommand. -
The command works with files that have a
.lua
extension -
The command also works with non-saved buffers that are named with a
.lua
extension. For example, you can do:e tmp.lau
, write some code and run it with:so
, then delete the buffer with:bd!
-
The
:so
command 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:so
and: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