Vim Snippets for Corona SDK and Lua Development

In my last post I showed you how to set up Vim for Corona SDK development. The environment I described in it has a lot of room for improvement. One of these is code snippets.

This post will show you how to add Corona SDK and Lua code snippets to the Vim editor.

How to Set up Snippets Support for Corona

To support code snippets in Vim you need the snipMate plugin.

  1. Download the snipMate plug-in bundle snipMate.zip.
  2. Open Terminal and change the directory to where you saved the snipMate.zip file.
  3. Unzip the file with the command unzip -d snipMate.zip ~/.vim
  4. To enable the help file for the plug-in run the following command from within Vim: :helptags ~/.vim/doc

The Snippets File

Now download the lua.snippets file for Corona SDK and place it in the folder ~/.vim/snippets/.

The snippets file is heavily based on the TextMate editor bundle for Corona. Many thanks to Darren Osadchuk from Ludicrous Software. If you are using TextMate for the development of Corona SDK apps, check out his site and the TextMate bundle.

How to Use the Snippets

You can use the snippets by entering the snippets trigger and pressing the tab key while in insert mode. For example enter the word forp (the snippets trigger) while in insert mode and then press the tab key. This will result in the following code:

  for key, value in pairs( table_name ) do
    print( key, value )
  end

You can now use the tab key to cycle through key, value, and table_name. Use shift-tab to jump backwards.

To see a list of the supported snippet triggers open the snippets file ~/.vim/lua.snippets.

You can also use auto-completion for the snippets. Try this: while in insert mode enter the word native and then press the key combination control-r followed by the tab key. This should open a box where you can select a code snippet using the arrow keys.

![Vim for Corona SDK](Corona-SDK-Lua-Vim-Snippets.png "Vim for Corona SDK")
Vim for Corona SDK

The snippets are working if you edit a file with the file extension .lua. If you want to use the snippets in other files you need to set the file type in Vim with the command:

  :set filetype=lua

Improvements

This is the first version of the snippets file. If you want to help to improve the file, please let me know and I will upload the file to GitHub.

Conclusion

With snippets support we have added one more piece to make Vim the missing Corona SDK IDE.

If you find this post useful, please subscribe to the RSS feed, or follow me on Twitter.


Jo's Profile ImageWritten by Jo Meenen who lives and works in Frankfurt building digital doodah. Stalk him on Twitter

ImpressumDatenschutz