Created
March 4, 2018 13:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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