This is a stripped-down version of vim-lua for use with LuaLS or other LSP servers. It excludes completion, syntax checking, and other redundant features. I wanted to simplify my lua setup to reduce any potential sources of errors. See the deluxe branch or Peter Odding's original lua ftplugin for a version that includes more features (most are toggleable).
The Lua file type plug-in for Vim makes it easier to work with Lua source code in Vim by providing the following features:
-
The 'includeexpr' option is set so that the gf (go to file) mapping knows how to resolve Lua module names using package.path
-
The 'include' option is set so that Vim follows dofile(), loadfile() and require() calls when looking for identifiers in included files (this works together with the 'includeexpr' option)
-
K
(normal mode) and<F1>
(insert mode) on a Lua function or 'method' call will try to open the relevant documentation in the Lua Reference for Vim -
Several text-objects are defined so you can jump between blocks and functions
-
A pretty nifty hack of the matchit plug-in is included: When the cursor is on a
function
orreturn
keyword the%
mapping cycles between the relevant keywords (function
,return
,end
), this also works for branching statements (if
,elseif
,else
,end
) and looping statements (for
,while
,repeat
,until
,end
)
Install this plugin and the vim-misc plugin with vim-plug or similar plugin manager:
Plug 'idbrii/vim-lua-ftplugin'
Plug 'xolox/vim-misc'
Or clone these two repositories into ~/.vim/pack/lua-ftplugin/start
Now try it out: Edit a Lua script and try any of the features documented above.
The Lua file type plug-in handles options as follows: First it looks at buffer local variables, then it looks at global variables and if neither exists a default is chosen. This means you can change how the plug-in works for individual buffers. For example to change the location of the Lua compiler used to check the syntax:
" This sets the default value for all buffers.
:let g:lua_interpreter_path = '/usr/local/bin/lua'
" This is how you change the value for one buffer.
:let b:lua_interpreter_path = '/usr/local/bin/lua52'
The name or path of the Lua interpreter used to evaluate Lua scripts used by the plug-in (for example the script that checks for undefined global variables, see :LuaCheckGlobals
).
If you're running a version of Vim that supports the Lua Interface for Vim (see if_lua.txt) then all Lua code evaluated by the Lua file type plug-in is evaluated using the Lua Interface for Vim. If the Lua Interface for Vim is not available the plug-in falls back to using an external Lua interpreter. You can set this to false (0) to force the plug-in to use an external Lua interpreter.
If you have suggestions or feature requests, first check out the deluxe version https://github.com/idbrii/vim-lua-ftplugin/tree/deluxe or the original at http://peterodding.com/code/vim/lua-ftplugin .
If you have any issues with this simplified version, see https://github.com/idbrii/vim-lua-ftplugin/issues
This software is licensed under the MIT license. © 2014 Peter Odding <[email protected]>.
Thanks go out to everyone who has helped to improve the Lua file type plug-in for Vim (whether through pull requests, bug reports or personal e-mails).