Add Snippets command for UltiSnips
This commit is contained in:
parent
ff406e34bf
commit
c428193bc0
2 changed files with 28 additions and 0 deletions
|
@ -41,6 +41,7 @@ List of commands
|
|||
| `BTags` | Tags in the current buffer |
|
||||
| `Locate PATTERN` | `locate` command output |
|
||||
| `History` | `v:oldfiles` and open buffers |
|
||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||
|
||||
- All commands except `Colors` support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
||||
bindings to open in a new tab, a new split, or in a new vertical split.
|
||||
|
@ -66,3 +67,4 @@ MIT
|
|||
[run]: https://github.com/junegunn/fzf#usage-as-vim-plugin
|
||||
[vimrc]: https://github.com/junegunn/dotfiles/blob/master/vimrc
|
||||
[ag]: https://github.com/ggreer/the_silver_searcher
|
||||
[us]: https://github.com/SirVer/ultisnips
|
||||
|
|
|
@ -338,6 +338,32 @@ endfunction
|
|||
|
||||
command! -bang Tags call s:tags(<bang>0)
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
" Snippets (UltiSnips)
|
||||
" ------------------------------------------------------------------
|
||||
function! s:inject_snippet(line)
|
||||
let snip = split(a:line, "\t")[0]
|
||||
execute 'normal! a'.s:strip(snip)."\<c-r>=UltiSnips#ExpandSnippet()\<cr>"
|
||||
endfunction
|
||||
|
||||
function! s:snippets(bang)
|
||||
if !exists(':UltiSnipsEdit')
|
||||
return s:warn('UltiSnips not found')
|
||||
endif
|
||||
let list = UltiSnips#SnippetsInCurrentScope()
|
||||
if empty(list)
|
||||
return s:warn('No snippets available here')
|
||||
endif
|
||||
let aligned = sort(s:align_lists(items(list)))
|
||||
let colored = map(aligned, 's:yellow(v:val[0], 1)."\t".v:val[1]')
|
||||
call s:fzf({
|
||||
\ 'source': colored,
|
||||
\ 'options': '--ansi +m -n 1 -d "\t"',
|
||||
\ 'sink': function('s:inject_snippet')}, a:bang)
|
||||
endfunction
|
||||
|
||||
command! -bang Snippets call s:snippets(<bang>0)
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
|
Loading…
Add table
Reference in a new issue