Snippets in all type of editors are very usefull beings that every bloger/programmer should start using. Especially if using ViM. Check out what solution I've found that supports snippets for vim!



There is a great snippets solution for Vim UltiSnips created iniatially by Holger Rapp, that is also recommended by Django Team at Vim Hints.

Let's check out what they are all about!

Installing UltiSnips

First of all, you need to install your UltiSnips.

As usually I'm recommending Vundle that makes installing of vim-plugins much easier.

Let's do it. Add this line in your .vimrc file:

" Track the engine.
Plugin 'SirVer/ultisnips'

" Snippets are separated from the engine. Add this if you want them:
Plugin 'honza/vim-snippets'

" Trigger configuration. Do not use <tab> if you use
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"

" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"

Now as usually make installation of this plugin with:

vim +PluginInstall +qall

UltiSnips Templates

When you follow steps above, you will have already predefined templates from honza/vim-snippets repository

You can check those templates in your vim-bundle directory at:

ls -al ~/.vim/bundle/vim-snippets/UltiSnips/

I personally checked the source code for preexisting python snippet to know which snippets are available.

Using UltiSnips

When we copy-pasted changes to vimrc file, there was a "UltiSnipsExpandTrigger", "UltiSnipsJumpForwardTrigger" and "UltiSnipsJumpBackwardTrigger".

They are in fact a binding to which key-stroke special action should be used. It means, that using in our case a "Tab" after writing name of the snippet i.e. :


will make use of preexisting deff snippet and paste it to our code/text.

Those snippets have special moving triggers, which applies to move forward/backward within snippet elements to be changed.

Where to go now?

I used those videos and it helped me to learn how to use this powerful feature.



I'd like to address a special thanks for #miroburn for challenging me in making a 30-day blog-posting! It was a great experience!

See you in the next episode soon! Cheers!


comments powered by Disqus