Already awesome
If you haven’t tried snipMate, you have to give it a test-drive. If you want to define a new ruby class in Vim, type “cla<tab>” and you’re presented with your choice of class templates:

Enter a number, and the code is automagically generated for you.
The tweak
By default, hitting enter at the menu cancels the snippet. However, a user can already easily cancel using escape, and this probably won’t happen all that often anyway (I don’t think ever for me). So I altered the code to choose the first (most common) snippet if no number is entered. This saves me a non-home-row keystroke in almost 100% of my usage.
The code
In plugin/snipMate.vim, comment out the last line of the s:ChooseSnippet function and add two lines in it’s place:
fun s:ChooseSnippet(scope, trigger)
[snip...]
" Original last line (which cancels on enter) commented out
"return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
" Two lines added to choose first snippet if none are selected
let snip_to_return = num == -1 ? 0 : num
return s:multi_snips[a:scope][a:trigger][snip_to_return][1]
endf
Pretty simple, huh? Oh, just remember to save a copy of the changed lines somewhere. When you update the plugin, your changes will be erased and you’ll have to re-paste them.
Awesome plug-in! Uh, ok… but what the heck does it do?!?! Here’s a list of the goodness:

- Jump to steps
- CTRL-] opens the step definition in the current window
- CTRL-W ] opens it in a split window (optionally hold CTRL with the ‘]’)
- CTRL-W opens in a split preview window
- Autocomplete – it seems from the source that it should work, but I can’t get it going. I posted a question on the cucumber mailing list.
It is unbelievably easy to create a wicked setup, although I spent half a day googling to narrow it down to the exsentials:
Downloads
- Ruby with the One-click installer.
- Vim’s self-installing Windows executable (this comes with many customizations you read about online, and ruby support, included)
- snipMate, a plug-in that automatically expands common Ruby constructs (e.g. you type ‘cla<tab>,’ which becomes class…end with placeholders!)
- AutoComplPop (must have!!!), an autocomplete plugin very much like Xcode’s – start typing and a popup list of completion options appears. superTab, another plug-in that allows you to use tab to auto-complete Ruby code
- wombat, a great color scheme
Global configurations
Add the following settings to /path/to/vim/_vimrc.
note: the autocomplete menu colors, and vim’s default font are disgusting, hence the changes.
Ruby-specific Configurations
In the vimrc above, the following is added:
- the first line sets up superTabs to look in the right place for Ruby completions (I use AutoComplPop now, see above)
adds line numbers to several source code file types
changes the ridiculous 8-space tabs to 2
That’s it! Happy coding
Recent Comments