add unite source
This commit is contained in:
parent
4b4ee48858
commit
cc15145429
56
autoload/unite/sources/ultisnips.vim
Normal file
56
autoload/unite/sources/ultisnips.vim
Normal file
@ -0,0 +1,56 @@
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:unite_source = {
|
||||
\ 'name': 'ultisnips',
|
||||
\ 'hooks': {},
|
||||
\ 'action_table': {},
|
||||
\ 'default_action': 'expand',
|
||||
\ }
|
||||
|
||||
let s:unite_source.action_table.preview = {
|
||||
\ 'description' : 'ultisnips snippets',
|
||||
\ 'is_quit' : 0,
|
||||
\ }
|
||||
|
||||
function! s:unite_source.action_table.preview.func(candidate)
|
||||
" no nice preview at this point, cannot get snippet text
|
||||
let snippet_preview = a:candidate['word']
|
||||
echo snippet_preview
|
||||
endfunction
|
||||
|
||||
let s:unite_source.action_table.expand = {
|
||||
\ 'description': 'expand the current snippet',
|
||||
\ 'is_quit': 1
|
||||
\}
|
||||
|
||||
function! s:unite_source.action_table.expand.func(candidate)
|
||||
let delCurrWord = (getline(".")[col(".")-1] == " ") ? "" : "diw"
|
||||
exe "normal " . delCurrWord . "a" . a:candidate['trigger'] . " "
|
||||
call UltiSnips#ExpandSnippet()
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! s:unite_source.gather_candidates(args, context)
|
||||
let default_val = {'word': '', 'unite__abbr': '', 'is_dummy': 0, 'source':
|
||||
\ 'ultisnips', 'unite__is_marked': 0, 'kind': 'command', 'is_matched': 1,
|
||||
\ 'is_multiline': 0}
|
||||
let snippet_list = UltiSnips#SnippetsInCurrentScope()
|
||||
let canditates = []
|
||||
for snip in items(snippet_list)
|
||||
let curr_val = copy(default_val)
|
||||
let curr_val['word'] = snip[0] . " " . snip[1]
|
||||
let curr_val['trigger'] = snip[0]
|
||||
call add(canditates, curr_val)
|
||||
endfor
|
||||
return canditates
|
||||
endfunction
|
||||
|
||||
function! unite#sources#ultisnips#define()
|
||||
return s:unite_source
|
||||
endfunction
|
||||
|
||||
"unlet s:unite_source
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
@ -1284,6 +1284,16 @@ offers a really nice completion dialogue for snippets.
|
||||
neocomplete - UltiSnips ships with a source for neocomplete and therefore
|
||||
offers out of the box completion dialogue support for it too.
|
||||
|
||||
unite - similarly to neocomplete UltiSnips now has a source for unite.
|
||||
As an example of how you can use the unite source add the following mappings to
|
||||
your vimrc:
|
||||
|
||||
nnoremap <silent> <F12> :Unite -start-insert ultisnips<CR>
|
||||
inoremap <silent> <F12> <ESC>:Unite -start-insert ultisnips<CR>
|
||||
|
||||
Then typing <F12> in either insert or normal mode you will get unite interface
|
||||
with matching snippets. Pressing enter will expand the corresponding snippet.
|
||||
|
||||
Supertab - UltiSnips has built-in support for Supertab. Just use a recent
|
||||
enough version of both plugins and <tab> will either expand a snippet or defer
|
||||
to Supertab for expansion.
|
||||
|
Loading…
Reference in New Issue
Block a user