|
| 1 | +*ft_lua.txt* Lua file type plug-in for the Vim text editor |
| 2 | + |
| 3 | +The Lua [1] file type plug-in for Vim makes it easier to work with Lua source |
| 4 | +code in Vim by providing the following features: |
| 5 | + |
| 6 | + - The |'includeexpr'| option is set so that the |gf| (go to file) mapping knows |
| 7 | + how to resolve Lua module names using package.path [2] |
| 8 | + |
| 9 | + - The |'include'| option is set so that Vim follows dofile() [3], loadfile() [4] |
| 10 | + and require() [5] calls when looking for identifiers in included files |
| 11 | + (this works together with the |'includeexpr'| option) |
| 12 | + |
| 13 | + - An automatic command is installed that runs 'luac -p' when you save your Lua |
| 14 | + scripts. If 'luac' reports any errors they are shown in the quick-fix list |
| 15 | + and Vim jumps to the line of the first error. If 'luac -p' doesn't report |
| 16 | + any errors a check for undefined global variables is performed by parsing |
| 17 | + the output of 'luac -p -l' |
| 18 | + |
| 19 | + - '<F1>' on a Lua function or 'method' call will try to open the relevant |
| 20 | + documentation in the Lua Reference for Vim [6] |
| 21 | + |
| 22 | + - The |'completefunc'| option is set to allow completion of Lua 5.1 keywords, |
| 23 | + global variables and library members using Control-X Control-U |
| 24 | + |
| 25 | + - The |'omnifunc'| option is set to allow dynamic completion of the variables |
| 26 | + defined in all modules installed on the system using Control-X Control-O, |
| 27 | + however it needs to be explicitly enabled by setting the |
| 28 | + |lua_complete_omni| option because this functionality may have undesired |
| 29 | + side effects! When you invoke omni completion after typing 'require '' or |
| 30 | + 'require('' you get completion of module names |
| 31 | + |
| 32 | + Screenshot of omni completion, see reference [7] |
| 33 | + |
| 34 | + - Several |text-objects| are defined so you can jump between blocks and |
| 35 | + functions |
| 36 | + |
| 37 | + - A pretty nifty hack of the matchit plug-in (see |matchit-install|) is |
| 38 | + included: When the cursor is on a 'function' or 'return' keyword the '%' |
| 39 | + mapping cycles between the relevant keywords ('function', 'return', 'end'), |
| 40 | + this also works for branching statements ('if', 'elseif', 'else', 'end') |
| 41 | + and looping statements ('for', 'while', 'repeat', 'until', 'end') |
| 42 | + |
| 43 | +=============================================================================== |
| 44 | + *ft_lua-installation* |
| 45 | +Installation ~ |
| 46 | + |
| 47 | +Unzip the most recent ZIP archive [8] file inside your Vim profile directory |
| 48 | +(usually this is '~/.vim' on UNIX and '%USERPROFILE%\vimfiles' on Windows), |
| 49 | +restart Vim and execute the command ':helptags ~/.vim/doc' (use ':helptags |
| 50 | +~\vimfiles\doc' instead on Windows). Now try it out: Edit a Lua script and try |
| 51 | +any of the features documented above. |
| 52 | + |
| 53 | +=============================================================================== |
| 54 | + *ft_lua-options* |
| 55 | +Options ~ |
| 56 | + |
| 57 | +The Lua file type plug-in handles options as follows: First it looks at buffer |
| 58 | +local variables, then it looks at global variables and if neither exists a |
| 59 | +default is chosen. This means you can change how the plug-in works for |
| 60 | +individual buffers. For example to change the location of the Lua compiler |
| 61 | +used to check the syntax: |
| 62 | +> |
| 63 | + " This sets the default value for all buffers. |
| 64 | + :let g:lua_compiler_name = '/usr/local/bin/luac' |
| 65 | + |
| 66 | + " This is how you change the value for one buffer. |
| 67 | + :let b:lua_compiler_name = '/usr/local/bin/lualint' |
| 68 | +
|
| 69 | +------------------------------------------------------------------------------- |
| 70 | +The *lua_path* option |
| 71 | + |
| 72 | +This option contains the value of 'package.path' as a string. You shouldn't |
| 73 | +need to change this because the plug-in is aware of $LUA_PATH [2] and if that |
| 74 | +isn't set the plug-in will run a Lua interpreter to get the value of |
| 75 | +package.path [2]. |
| 76 | + |
| 77 | +------------------------------------------------------------------------------- |
| 78 | +The *lua_check_syntax* option |
| 79 | + |
| 80 | +When you write a Lua script to disk the plug-in automatically runs the Lua |
| 81 | +compiler to check for syntax errors. To disable this behavior you can set this |
| 82 | +option to false (0): |
| 83 | +> |
| 84 | + let g:lua_check_syntax = 0 |
| 85 | +
|
| 86 | +You can manually check the syntax using the ':CheckSyntax' command. |
| 87 | + |
| 88 | +------------------------------------------------------------------------------- |
| 89 | +The *lua_check_globals* option |
| 90 | + |
| 91 | +When you write a Lua script to disk the plug-in automatically runs the Lua |
| 92 | +compiler to check for undefined global variables. To disable this behavior you |
| 93 | +can set this option to false (0): |
| 94 | +> |
| 95 | + let g:lua_check_globals = 0 |
| 96 | +
|
| 97 | +You can manually check the globals using the ':CheckGlobals' command. |
| 98 | + |
| 99 | +------------------------------------------------------------------------------- |
| 100 | +The *lua_compiler_name* option |
| 101 | + |
| 102 | +The name or path of the Lua compiler used to check for syntax errors (defaults |
| 103 | +to 'luac'). You can set this option to run the Lua compiler from a |
| 104 | +non-standard location or to run a dedicated syntax checker like lualint [9]. |
| 105 | + |
| 106 | +------------------------------------------------------------------------------- |
| 107 | +The *lua_compiler_args* option |
| 108 | + |
| 109 | +The argument(s) required by the compiler or syntax checker (defaults to '-p'). |
| 110 | + |
| 111 | +------------------------------------------------------------------------------- |
| 112 | +The *lua_error_format* option |
| 113 | + |
| 114 | +If you use a dedicated syntax checker you may need to change this option to |
| 115 | +reflect the format of the messages printed by the syntax checker. |
| 116 | + |
| 117 | +------------------------------------------------------------------------------- |
| 118 | +The *lua_complete_keywords* option |
| 119 | + |
| 120 | +To disable completion of keywords you can set this option to false (0). |
| 121 | + |
| 122 | +------------------------------------------------------------------------------- |
| 123 | +The *lua_complete_globals* option |
| 124 | + |
| 125 | +To disable completion of global functions you can set this option to false |
| 126 | +(0). |
| 127 | + |
| 128 | +------------------------------------------------------------------------------- |
| 129 | +The *lua_complete_library* option |
| 130 | + |
| 131 | +To disable completion of library functions you can set this option to false |
| 132 | +(0). |
| 133 | + |
| 134 | +------------------------------------------------------------------------------- |
| 135 | +The *lua_complete_dynamic* option |
| 136 | + |
| 137 | +When you type a dot after a word the Lua file type plug-in will automatically |
| 138 | +start completion. To disable this behavior you can set this option to false |
| 139 | +(0). |
| 140 | + |
| 141 | +------------------------------------------------------------------------------- |
| 142 | +The *lua_complete_omni* option |
| 143 | + |
| 144 | +This option is disabled by default for two reasons: |
| 145 | + |
| 146 | + - The omni completion support works by enumerating and loading all installed |
| 147 | + modules. If module loading has side effects this can have unintended |
| 148 | + consequences! |
| 149 | + |
| 150 | + - Because all modules installed on the system are loaded, collecting the |
| 151 | + completion candidates can be slow. After the first run the completion |
| 152 | + candidates are cached so this will only bother you once (until you restart |
| 153 | + Vim). |
| 154 | + |
| 155 | +If you want to use the omni completion despite the warnings above, execute the |
| 156 | +following command: |
| 157 | +> |
| 158 | + :let g:lua_complete_omni = 1 |
| 159 | +
|
| 160 | +Now when you type Control-X Control-O Vim will hang for a moment, after which |
| 161 | +you should be presented with an enormous list of completion candidates :-) |
| 162 | + |
| 163 | +=============================================================================== |
| 164 | + *ft_lua-contact* |
| 165 | +Contact ~ |
| 166 | + |
| 167 | +If you have questions, bug reports, suggestions, etc. the author can be |
| 168 | +contacted at peter@peterodding.com. The latest version is available at |
| 169 | +http://peterodding.com/code/vim/lua-ftplugin and http://github.com/xolox/vim-lua-ftplugin. |
| 170 | +If you like this plug-in please vote for it on Vim Online [10]. |
| 171 | + |
| 172 | +=============================================================================== |
| 173 | + *ft_lua-license* |
| 174 | +License ~ |
| 175 | + |
| 176 | +This software is licensed under the MIT license [11]. Copyright 2011 Peter |
| 177 | +Odding <peter@peterodding.com>. |
| 178 | + |
| 179 | +=============================================================================== |
| 180 | + *ft_lua-references* |
| 181 | +References ~ |
| 182 | + |
| 183 | +[1] http://www.lua.org/ |
| 184 | +[2] http://www.lua.org/manual/5.1/manual.html#pdf-package.path |
| 185 | +[3] http://www.lua.org/manual/5.1/manual.html#pdf-dofile |
| 186 | +[4] http://www.lua.org/manual/5.1/manual.html#pdf-loadfile |
| 187 | +[5] http://www.lua.org/manual/5.1/manual.html#pdf-require |
| 188 | +[6] http://www.vim.org/scripts/script.php?script_id=1291 |
| 189 | +[7] http://peterodding.com/code/vim/lua-ftplugin/screenshots/omni-completion.png |
| 190 | +[8] http://peterodding.com/code/vim/downloads/lua-ftplugin.zip |
| 191 | +[9] http://lua-users.org/wiki/LuaLint |
| 192 | +[10] http://www.vim.org/scripts/script.php?script_id=3625 |
| 193 | +[11] http://en.wikipedia.org/wiki/MIT_License |
| 194 | + |
| 195 | +vim: ft=help |
0 commit comments