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!
S0-E30/E30
UltiSnips
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 https://github.com/Valloric/YouCompleteMe.
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. :
deff<TAB>
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?
-
Holdger Rapp (author of UltiSnipps) YT video UltiSnips Playlist, EP1, EP2, EP3, EP4
-
VimCasts Videos - You can also check how to use this UltiSnips with videos from vimcasts.
-
Gitter communicator for UltiSnips - a place where community paste they problems and solves them. Check at SirVer/Ultisnips
I used those videos and it helped me to learn how to use this powerful feature.
Acknowledgements
- UltiSnips github repo
- Using Vim With Django
- Notes on using Vim with Python
- Meet UltiSnips at vimcasts
- Vim UltiSnips How do i move to the next placeholer or tabstop
Thanks!
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
comments powered by Disqus