Answer the question
In order to leave comments, you need to log in
How to make autocomplete and snippets work in vim?
I use YouCompleteMe for autocomplete and vim-snipmate for snippets . I would like to hang both plugins on Tab, so that there would be some kind of "smart" enumeration of options. If there is a snippet, then we write the snippet, if not, then we scroll through the autocomplete.
Tell me, is it possible to implement this?
Answer the question
In order to leave comments, you need to log in
Such a combination can be obtained in the bundle neocomplete.vim + ultisnips .
neocomplete requires Vim built with Lua support (why Lua was chosen is explained here ). Building and compiling under Linux is quite common and not difficult, but for Windows you can find a ready-made build from the current build version ( 1 , 2 , 3 and Lua itself ). UltiSnips requires python support, and it seems to be only version 2.
When configuring neocomplete, you need to add ultisnips as a source:
let g:neocomplete#sources = {
\ '_': ['buffer', 'file/include'],
\ 'javascript': ['omni', 'file/include', 'ultisnips', 'tag']
\}
call neocomplete#custom#source('ultisnips', 'rank', 100)
call neocomplete#custom#source('ultisnips', 'min_pattern_length', 1)
inoremap <silent> <Tab> <C-r>=<SID>neoComplete("\<Tab>")<CR>
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<C-x>\<C-o>"
function! s:neoComplete(key)
if pumvisible()
return "\<C-n>"
endif
let [curPos, lineLength] = [getcurpos()[4], col('$')]
let isText = curPos <= lineLength
let isStartLine = curPos <= 1
let isBackspace = getline('.')[curPos-2] =~ '\s'
if isText && !isStartLine && !isBackspace
return neocomplete#helper#get_force_omni_complete_pos(neocomplete#get_cur_text(1)) >= 0
\ ? "\<C-x>\<C-o>\<C-r>=neocomplete#mappings#popup_post()\<CR>"
\ : neocomplete#start_manual_complete()
endif
return a:key
endfunction
inoremap <silent> ` <C-r>=<SID>ultiComplete("\`")<CR>
xnoremap <silent> ` :<C-u>call UltiSnips#SaveLastVisualSelection()<CR>gvs
snoremap <C-c> <Esc>
function! s:ultiComplete(key)
if len(UltiSnips#SnippetsInCurrentScope()) >= 1
let [curPos, lineLength] = [getcurpos()[4], col('$')]
let isBackspace = getline('.')[curPos-2] =~ '\s'
let isStartLine = curPos <= 1
let isText = curPos <= lineLength
if isText && !isStartLine && !isBackspace
return UltiSnips#ExpandSnippet()
endif
endif
return a:key
endfunction
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question