This article is part of the article series "Vim Plugins You Should Know About."
<- previous article next article ->
Vim Plugins, surround.vim

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
  • 2. Extract 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!

This article is part of the article series "Vim Plugins You Should Know About."
<- previous article next article ->


August 04, 2009, 11:14

Very cool!

August 04, 2009, 13:00

Oh, what would I do without my snippets :)

August 04, 2009, 13:02

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 04, 2009, 13:03

Oh and thank you for your great blogpost :-)

August 04, 2009, 13:08

"And that smells like emacs."

And it smells good. :)

JOhn Dingo Permalink
August 04, 2009, 13:32

Wow, that is truly amazing dude. Well done!

August 04, 2009, 13:47

This is great thanks. What do you do if you just want a tab after a word which happens to be a keyword?

jva Permalink
August 04, 2009, 14:05

This is an upgrade for my simple abbrevs.

:ab for for(i=0; i}

Paul Oyster Permalink
August 04, 2009, 15:07

Did you test the excellent snippetsEmu? How do the two compare?

xxx Permalink
June 13, 2010, 12:36

The main difference is that snipmate is more robust when you are within a snippet, whereas snippetsEMU requires you to tab through the snippet before you can edit it. In other words, snippetsEMU gets confused if you enter and exit insert mode while processing a snippet. Also, the built-in completions for snipmate are simpler and the menu that allows you to choose multiple options for a given completion is nice so you don't have to remember a list of prefix words. Otherwise, they are very similar.

August 04, 2009, 16:10

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 04, 2009, 20:03

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.

fouad Permalink
August 05, 2009, 08:52

which colorschem are you using ?!

July 18, 2010, 12:08

i use the default color scheme too!

August 05, 2009, 09:01

fouad, I use the default color scheme.

August 05, 2009, 09:37

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 :)

ypetya Permalink
August 05, 2009, 14:06

thanx!!! It's very cool

August 07, 2009, 12:44

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 ?

wohoo Permalink
July 28, 2010, 03:32

i have same problem too. How to mix PHP, HTML, and JavaScript snippets ?

Wamith Permalink
October 06, 2010, 13:15

Add the following line to your .vimrc file toget php and html snippets:

au BufRead,BufNewFile *.php set filetype=php.html

August 08, 2009, 19:16

Offtopic: Wich color scheme are you using in the screencast ?

August 09, 2009, 02:47

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!

argv Permalink
August 10, 2009, 21:50

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.

scum Permalink
July 12, 2010, 02:37

I was at a seminar by Ken Sipe. One (actually many things) thing really made sense to me. For whatever technology you are using, your level of knowledge should be one level deeper. So, in this case, if you are using snippets, you should know vim, *well*. So, portability is not really a concern because the customization is an enhancement to your knowledge.

ypetya Permalink
August 11, 2009, 09:28

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.

KsiadzGrucha Permalink
August 18, 2009, 23:58

Neato! :)

September 30, 2009, 23:15

Maybe Taglist should be the number V?:)

October 02, 2009, 21:48

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 in that such that all the subdirs are under .vim/
4. put the following line in your .vimrc file you created earlier:

filetype plugin on

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.

Bart J Permalink
February 17, 2010, 11:11

This blog post is similar to - is this some form of plagiarism of your content?

February 17, 2010, 12:33

Bart J, thanks for noticing, I just sent them a notice to remove all the articles.

Umesh Permalink
February 17, 2011, 15:57

If I modify a snippet file, how do I reload ?

May 31, 2011, 10:53

snipmate plugin hasn't been updated for a long long time. thats why i started a friendly fork and i'm merging and coordinating further development of this (at least for me) essential plugin.

more here:

xxx Permalink
September 02, 2011, 23:29

You should also consider Ultisnips, which allows for embedded Python code inside snippets. this means you can dynamically evaluated expressions that are part of snippets.

GrouchyGaijin Permalink
January 28, 2013, 17:19

I wish I could get this working. I'm on Ubuntu 12.04 and think I followed the instructions, but a tab is just a tab. I have no text expansion.

Leave a new comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "rocket_151": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.