lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi list!

This is going to be a long message so if you're not interested in Vim, 'nothing to see here, move along'. Otherwise, please bear with me :)

So I've been busy learning Vim for a while now, especially Vim script because it allows me to script my development environment. One very nice feature of Vim is support for file type plug-ins. Unfortunately the Lua file type plug-in [1] was last updated in 2001 and isn't very useful. I've been working on a more full featured Lua file type plug-in for a few months now, and I'm getting pretty happy with the results. I'm considering submitting the plug-in for inclusion in the Vim runtime files but before I do that I want to make sure that:

 * The plug-in works for more than one person...
 * Lua-l agrees with the configuration defaults I've chosen
 * There's no missing features that would be great to include

An overview of the significant things my file type plug-in will do to your beloved Vim configuration (when your editing Lua source code):

* The 'includeexpr' option is set so that the gf (go to file) mapping knows how to resolve Lua module names using the $LUA_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).

* An automatic command is installed that runs 'luac -p' when you save your Lua scripts. If luac reports any errors they are shown in the quick-fix list and Vim jumps to the line of the first error.

* <F1> on a Lua function or 'method' call will try to open the relevant documentation in the Lua Reference for Vim [2].

* The 'usercomplete' option is set to allow completion of Lua 5.1 keywords, global variables and library members.

* A bunch of 'text object' mappings are included 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' or 'return' keyword the % mapping cycles between the relevant 'function', 'return' and 'end' keywords. Likewise for branching statements (if, elseif, else, end) and looping statements (for, while, repeat, until, end).

If you've read this far, thanks for your time! There's bound to be bugs and it's ~370 lines of code excluding the generated completion list, so I might have overlooked some things. Anyways, if you want to try it out, drop the attached lua.vim script in your local /ftplugin/ directory (e.g. $HOME/vimfiles/ftplugin/lua.vim under Windows or ~/.vim/ftplugin/lua.vim under UNIX) and start editing some Lua source code. I hope you like it!

All feedback welcome,

 - Peter Odding

PS. Since my OS is UNIX the script uses \n instead of say \r\n to end lines. Vim *might* not like this, see the help topic 'source_crnl'. If Vim complains then just open the file in Vim and write it out under the correct 'fileformat'.


Attachment: lua.vim
Description: application/extension-vim