I would like to list the available snippets using a simple keystroke. However I can't seem to do this. Here are my UltiSnips settings:
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsListSnippets="<c-;>"
let g:UltiSnipsSnippetsDir="~/.vim/ultisnips"
let g:UltiSnipsEditSplit="vertical"
"Open UltiSnips edit function
nmap <leader>se :UltiSnipsEdit<cr>
I do have vim-snippets installed and a few snippets of my own defined.
Nothing happens when I press CTRL-;
. I've tried changing the mapping to a variety of different keystrokes, but nothing happens. I thought some other plugin I'm using would be interfering with the chosen keystroke so I've changed it a number of times and still don't get the listing. Regardless of what setting I have, I can't see the list of snippets.
What magic must I invoke to see the list of snippets?
This is not working for me too!
But digging through the doc for Ultisnips
, I found an alternative: h UltiSnips#SnippetsInCurrentScope
. There's an example function GetAllSnippets()
in this help section, which returns the list
of snippets available for the current buffer, and it looks like this:
function! GetAllSnippets()
call UltiSnips#SnippetsInCurrentScope(1)
let list = []
for [key, info] in items(g:current_ulti_dict_info)
let parts = split(info.location, ':')
call add(list, {
\"key": key,
\"path": parts[0],
\"linenr": parts[1],
\"description": info.description,
\})
endfor
return list
endfunction
I am not sure what you're requirements are after the list of snippets are available. If you want to jump to the definition of the snippet, you can do so with the modified version of the function in the doc below. This populates and opens the quickfix list:
function! GetAllSnippets()
call UltiSnips#SnippetsInCurrentScope(1)
let list = []
for [key, info] in items(g:current_ulti_dict_info)
let parts = split(info.location, ':')
call add(list, {
\"text": key,
\"filename": parts[0],
\"lnum": parts[1],
\"context": info.description,
\})
endfor
call setqflist([], ' ', { 'title': 'Snippets', 'items' : list})
" Open Quickfix list as soon as it is populated
copen
endfunction
Alternatively, if you're using fzf-vim, you could use the :Snippets
command to list, fuzzy find and invoke the snippet.
I look stupid right now! :D The solution was right there in h g:UltiSnipsListSnippets
:
Be advised, that some terminal emulators don't send
<c-tab>
(and others, like<c-h>
) to the running program.
Looks like my terminal too was blocking both <C-tab>
and <C-;>
. Remapped to use <C-m>
and it still didn't work. That's because it's an insert mode mapping and I was trying in normal mode all this while!