Skip to content

Instantly share code, notes, and snippets.

@i-give-up
Created March 4, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i-give-up/ee3d2ea47d0311042dd366fabf680944 to your computer and use it in GitHub Desktop.
Save i-give-up/ee3d2ea47d0311042dd366fabf680944 to your computer and use it in GitHub Desktop.
Vim user command for use with UltiSnips to view a snippet's definition
"user-defined command for use with UltiSnips to view snippet definition
command! -complete=custom,ListSnippets -nargs=1 Snipe call ViewSnippet(<q-args>)
function! ViewSnippet(word)
"you have to call this function to populate `g:current_ulti_dict_info` with
"information about the available snippets
call UltiSnips#SnippetsInCurrentScope(1)
let dict = g:current_ulti_dict_info
if has_key(dict, a:word)
let matches = matchlist(dict[a:word].location, '\v(.*):(\d+)')
"show snippet definition in a quickfix window of height 15
execute "copen 20 | edit " . matches[1]
"move to the line containing definition
execute matches[2]
"delete buffer when it's no longer displayed in window
set bufhidden=wipe
else
echo a:word . " is not a trigger."
endif
endfunction
"Custom completion function for `Snipe' command
function! ListSnippets(A,L,P)
call UltiSnips#SnippetsInCurrentScope(1)
return join(keys(g:current_ulti_dict_info), "\n")
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment