I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.

This is the fourth post in the article series “Vim Plugins You Should Know About“. This time I am going to introduce you to a plugin called “snipmate.vim“.
If you are intrigued by this topic, I suggest that you subscribe to my posts! For the introduction and first post in this article series, follow this link - Vim Plugins You Should Know About, Part I: surround.vim.
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. He says he modeled this plugin after TextMate’s snippets.
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; i<n; 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:
How to install snipmate.vim?
To get the latest version:
- 1. Download snipmate.zip.
- 2. Extract snipmate.zip to ~/.vim (on Unix/Linux) or ~\vimfiles (on Windows).
- 3. Run :helptags ~/.vim/doc (on Unix/Linux) or :helptags ~/vimfiles/doc (on Windows) to rebuild the tags file (so that you can read :help snipmate.)
- 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, Mako templates, LaTeX, 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!
Have fun with this time saving plugin!
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)

(14 votes, average: 4.86 out of 5)
|
|
|


August 4th, 2009 at 11:14 am
Very cool!
August 4th, 2009 at 12:43 pm
[…] - WSJ.comPower up your website with the might of APIs | News | TechRadar UK[CSS]5 | reddit Vim Plugins You Should Know About, Part IV: snipmate.vim Pure genius. A student has designed a bike which can be folded completely into the space of […]
August 4th, 2009 at 1:00 pm
Oh, what would I do without my snippets :)
August 4th, 2009 at 1:02 pm
It looks very nice, but I do not like it at all because if you use too much of plugins or use plugins so big as this one, then you have no Vim anymore. You will get new editor which is not present anywhere except your own computer. It also encourages not to learn your editor but create your own. And that smells like emacs. Well, of course that is just my point of view.
August 4th, 2009 at 1:03 pm
Oh and thank you for your great blogpost :-)
August 4th, 2009 at 1:08 pm
“And that smells like emacs.”
And it smells good. :)
http://www.youtube.com/watch?v=vOj7btx3ATg
August 4th, 2009 at 1:32 pm
Wow, that is truly amazing dude. Well done!
August 4th, 2009 at 1:47 pm
This is great thanks. What do you do if you just want a tab after a word which happens to be a keyword?
August 4th, 2009 at 2:05 pm
This is an upgrade for my simple abbrevs.
:ab for for(i=0; i}
August 4th, 2009 at 2:43 pm
[…] Vim Plugins You Should Know About, Part IV: snipmate.vim - good coders code, great reusecatonmat.net […]
August 4th, 2009 at 3:07 pm
Did you test the excellent snippetsEmu? How do the two compare?
August 4th, 2009 at 4:10 pm
I would also like to know how snipmate compares to SnippetsEMU, as a dedicated SnippetsEMU user for well over a year now!
Snippets are indispensable to me at this point.
August 4th, 2009 at 8:03 pm
dum8d0g, yes, but you want to be effective. It’s you who’s working at the computer and you want to be fast as a japanese bullet train!
(the one who blogs), nice presentation. I like how it replaces the guards in header file.
Paul Oyster, I did not test the excellent snippetsEmu. I made my way from NERDsnippets to snipMate. I’ll try it out and write an article snippetsEmu vs. snipMate.
Aaron, me too. No snippets == dead.
August 5th, 2009 at 2:27 am
[…] Vim Plugins You Should Know About, Part IV: snipmate.vim - good coders code, great reuse (tags: Vim plugin programming plugins tips tools writing code) […]
August 5th, 2009 at 8:52 am
which colorschem are you using ?!
August 5th, 2009 at 9:01 am
fouad, I use the default color scheme.
August 5th, 2009 at 9:37 am
great!! ..I’ve been using a similar setup I’ve written years ago, but it is not as nearly as complete as this, though faster to work with :)
will be patching this up and possibly releasing a mod :)
August 5th, 2009 at 2:06 pm
thanx!!! It’s very cool
August 5th, 2009 at 9:04 pm
[…] Vim Plugins You Should Know About, Part IV: snipmate.vim – good … […]
August 7th, 2009 at 2:24 am
[…] Vim Plugins You Should Know About, Part IV: snipmate.vim […]
August 7th, 2009 at 12:44 pm
Very cool plugin.
By the way, as PHP files often mix HTML and PHP code, what would be the best way to include PHP snippets AND HTML snippets ?
August 8th, 2009 at 7:16 pm
Offtopic: Wich color scheme are you using in the screencast ?
August 9th, 2009 at 2:47 am
PA, that is a good question. I don’t have an answer at the moment.
benoror, that’s not my screencast, so I don’t know that either. Try to find that theme at vim color scheme project!
August 10th, 2009 at 12:33 am
I use these
NERD Tree ( screencast )
NERD Commenter
August 10th, 2009 at 9:50 pm
The merits of Vim aside, dum8d0g makes a point worth considering with respect to *all* software. Too much customisation.
How much is “too much”?
Consider if you were by chance left without all your customisations, and you had to get things done. How long would it take you to get back up to speed?
Learning to work with default configurations and “base” software, and to use the simplest means possible to accomplish tasks can be a beneficial practice. Among other things, it makes recovery easier, reduces fear of data loss and encourages *your* portability.
We have all perhaps at some time become enthused with the potentials of customisation. Indeed it is a channel for one’s creativity toward improving efficiency. But… do you agree that:
“Limitation breeds creativity”
For reasons I will not explain, not every computer will have Vim, perl, xargs, bash, etc. *But*… most all of them will have a very “old” line or stream editor and a very “old” shell. These programs are always present, decade after decade, for reasons I will not explain.
Personally, for text clips, I prefer the ::multiple copy-paste buffer:: of tmux (a GNU screen alternative). It is small, simple stable (more so than screen, in my experience), and it compiles easily. It allows, with some creativity, clips to be copied, stored, loaded and pasted across *all* applications, whether to or from the console or X windows. And of course one can set key bindings, just like Vim or screen.
August 11th, 2009 at 9:28 am
Ok, now. I’m trying to use it. But it conflicts with autocompletion. What now, should I remap the snip function to an “incompatible” key combo? Maybe I will try this way.
August 18th, 2009 at 11:58 pm
Neato! :)
September 30th, 2009 at 11:15 pm
Maybe Taglist should be the number V?:)
October 2nd, 2009 at 9:48 pm
to get this working on you cygwin install do this:
1. start cygwin (cygwin.bat or something to that effect)
2. create a .vim directory in your $HOME
2a. create a .vimrc file in your $HOME
3. unzip the snipmate.zip in that such that all the subdirs are under .vim/
4. put the following line in your .vimrc file you created earlier:
5. restart Vim
NOTE: you’re doing 2a. to make sure your Vim starts in ‘nocompatible’ mode as the snipmate plugin won’t work in VI compatibility mode which was default in my Cygwin install.
HTH those who are trying this on a cygwin on XP setup.
October 28th, 2009 at 4:11 pm
[…] http://www.catonmat.net/blog/vim-plugins-snipmate-vim/ Tags: Comentários (0) Trackbacks (0) Deixe um comentário […]
January 18th, 2010 at 2:58 pm
[…] Part IV: snipmate.vim - the best snippet plugin for vim […]
February 17th, 2010 at 11:11 am
This blog post is similar to - http://zinas.krabjiem.lv/blogi/vim-plugins-you-should-know-about-part-iv-snipmatevim/130463/ is this some form of plagiarism of your content?
February 17th, 2010 at 12:33 pm
Bart J, thanks for noticing, I just sent them a notice to remove all the articles.