Saturday, August 8, 2009

Vim plugin you must install

Ok why I am writing this post.Two reasons for it:
1) We have a Web Programming Lab this semester
2) I hardly use windows now:-). Using windows has exponentially decreased:-)

Snipmate.vim is probably the best snippets plugin for vim. A snippet is a piece of often-typed text or programming construct that you can insert into your document by using a trigger followed by a tab. It was written by Michael Sanders.

Here is an example usage of snipmate.vim. If you are a C programmer, then one of the most often used forms of a loop is “for (i=0; condition ; i++) {}”. Without snippets you’d have to type this out every time. Even though it takes just another second, these seconds can add to minutes throughout the day and minutes can add to hours over longer periods of time. Why waste your time this way? With snippets you can type just “for tab” and snipmate will insert this whole construct in your source code automatically! If “i” or “n” weren’t the variable you wanted to use, you can now use tab and shift-tab to jump to next/previous item in the loop and rename them!

Michael also created an introduction video for his plugin where he demonstrates how to use it. Check it out:

snipMate.vim Introductory Screencast from Michael Sanders on Vimeo.

How to install snipmate.vim?

To get the latest version:

1. Download
2. Extract to ~/.vim (on Unix/Linux) or ~/etc/vim (wherever vim is installed)
#pradeep@pradeep-laptop: sudo unzip -d ~/etc/vim (provided is in your HOME folder else provide the desired path)
3. Run :helptags ~/.vim/doc or ~/etc/vim/doc
4. Restart Vim.

The plugin comes with predefined snippets for more than a dozen languages (C, C++, HTML, Java, JavaScript, Objective C, Perl, PHP, Python, Ruby, Tcl, Shell, HTML, VimScript). Be sure to check out the snippet files in the “snippets” directory under your ~/.vim or ~\vimfiles directory.

If you need to define your own snippets (which you most likely will need), create a new file named “language-foo.snippets” in the “snippets” directory. For example, to define your own snippets for C language, you’d create a file called “c-foo.snippets” and place snippets in it.

To learn about snipmate snippet syntax, type “:help snipmate” and locate the syntax section in the help file.
Have Fun!

Post in your comments if any queries!