diff --git a/README.md b/README.md index 319a464..047b441 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/plugin/fzf.vim b/plugin/fzf.vim index f9870f8..49ec516 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -338,6 +338,32 @@ endfunction command! -bang Tags call s:tags(0) +" ------------------------------------------------------------------ +" Snippets (UltiSnips) +" ------------------------------------------------------------------ +function! s:inject_snippet(line) + let snip = split(a:line, "\t")[0] + execute 'normal! a'.s:strip(snip)."\=UltiSnips#ExpandSnippet()\" +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(0) + " ------------------------------------------------------------------ let &cpo = s:cpo_save unlet s:cpo_save