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.
- Download the snipMate plug-in bundle snipMate.zip.
- Open Terminal and change the directory to where you saved the snipMate.zip file.
- Unzip the file with the command
unzip -d snipMate.zip ~/.vim
- To enable the help file for the plug-in run the following command from within Vim:
The Snippets File
Now download the lua.snippets file for Corona SDK and place it in the folder
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
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.
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:
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.
With snippets support we have added one more piece to make Vim the missing Corona SDK IDE.