UltiSnips is the ultimate solution for snippets in Vim. It has tons of features and is very fast.
In this demo I am editing a python file. I first expand the #!
snippet, then
the class
snippet. The completion menu comes from
YouCompleteMe, UltiSnips also
integrates with deoplete. I can
jump through placeholders and add text while the snippet inserts text in other
places automatically: when I add Animal
as a base class, __init__
gets
updated to call the base class constructor. When I add arguments to the
constructor, they automatically get assigned to instance variables. I then
insert my personal snippet for print
debugging. Note that I left insert mode,
inserted another snippet and went back to add an additional argument to
__init__
and the class snippet was still active and added another instance
variable.
The official home of UltiSnips is at https://github.com/sirver/ultisnips. Please add pull requests and issues there.
UltiSnips was started in Jun 2009 by @SirVer. In Dec 2015, maintenance was handed over to @seletskiy.
-
Advanced snippets:
This assumes you are using Vundle. Adapt
for your plugin manager of choice. Put this into your .vimrc
.
" 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-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
UltiSnips comes with comprehensive documentation. As there are more options and tons of features I suggest you at least skim it.
From a gentle introduction to really advanced in a few minutes: The blog posts of the screencasts contain more advanced examples of the things discussed in the videos.
- Episode 1: What are snippets and do I need them?
- Episode 2: Creating Basic Snippets
- Episode 3: What's new in version 2.0
- Episode 4: Python Interpolation
Also the excellent Vimcasts dedicated three episodes to UltiSnips: