Ultisnips also offers an API usually mapped to <C-Tab>
UltiSnips#ListSnippets()
, you should use that in case you want to avoid typing the entire snippet name, although the chances of clashes will be more.
How to expand the snippet with only part of the trigger?
Question
I have vim with UltiSnips and it's working but only if I write the whole trigger. Is there a way to expand the snippet writing only a part of the trigger? I used to work with SnipMate and that works.
e.g.: If I have a trigger like follows:
snippet someTrigger
blah blah
endsnippet
It expand the snippet when I type:
someTrigger<tab>
But it doesn't when I type
some<tab>
Solution 2
OTHER TIPS
I will offer two examples right of the documentation of ultisnips (I am familiar with these because I wrote these particular examples myself).
First one, doesn't depend on any external plugins:
function! ExpandPossibleShorterSnippet()
if len(UltiSnips#SnippetsInCurrentScope()) == 1 "only one candidate...
let curr_key = keys(UltiSnips#SnippetsInCurrentScope())[0]
normal diw
exe "normal a" . curr_key
exe "normal a "
return 1
endif
return 0
endfunction
inoremap <silent> <C-L> <C-R>=(ExpandPossibleShorterSnippet() == 0? '': UltiSnips#ExpandSnippet())<CR>
this will make <CTRL-L>
expand current snippet if there is no other snippet matching what you already wrote.
Second example uses another plugin, unite
:
function! UltiSnipsCallUnite()
Unite -start-insert -winheight=100 -immediately -no-empty ultisnips
return ''
endfunction
inoremap <silent> <F12> <C-R>=(pumvisible()? "\<LT>C-E>":"")<CR><C-R>=UltiSnipsCallUnite()<CR>
nnoremap <silent> <F12> a<C-R>=(pumvisible()? "\<LT>C-E>":"")<CR><C-R>=UltiSnipsCallUnite()<CR>
If there is only one matching snippet it will work fine. If two snippets are present then a menu appears which gives you the option to choose from one of the matching options.
If you're just interested in matching either some
or someTrigger
, the simplest solution is probably to use a regex trigger:
snippet "some(Trigger)?" !r
blah blah
endsnippet
The !r identifies the trigger as a regex - note that a regex trigger must be enclosed in quotes. This will expand from either 'some' or 'someTrigger'.
See :help UltiSnips-adding-snippets