vim - UltiSnips not working with YCM

3.1k Views Asked by At

when I use YouCompleteMe and UltiSnips together, I encounter 2 errors:

  1. I can type a snip pattern and the YCM dropdown menu recognizes it, however when I tab down to the snip in the menu, I cannot expand it. I have tried remapping g:UltiSnipsExpandTrigger to several different key (c-l, c-j, c-k, c-l, F5) and still have no success. I have yet to see UltiSnips actually expand a snippet.
  2. When I open a new file, e.g. a.py, YCM does not recognize ultisnippets in the file. I am basically trying to recreate the usage demonstrated in the nice gif on the ultisnips git page. Typing #! is not recognized by YCM, but if I open an already saved python file, #! will be recognized.

Perhaps these two problems are related.

Thanks for your time.

2

There are 2 best solutions below

1
On BEST ANSWER

I solved this problem with the following configurations:

UltiSnips:

let g:UltiSnipsSnippetsDir        = $HOME.'/.vim/UltiSnips/'
let g:UltiSnipsSnippetDirectories=["UltiSnips"]
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
let g:UltiSnipsListSnippets="<c-h>"

YCM:

let g:ycm_complete_in_comments = 1 
let g:ycm_seed_identifiers_with_syntax = 1 
let g:ycm_collect_identifiers_from_comments_and_strings = 1 
3
On

I had the same issue with making both of them work together.

here is my .vimrc, you might find what you need:

" ----------------------------------------------------------------------------
" Autocompletion & Snippets Plugins
" ----------------------------------------------------------------------------

if has('nvim')
    runtime! python_setup.vim
endif

Plug 'Valloric/YouCompleteMe', { 'do': './install.sh --clang-completer' }
Plug 'SirVer/ultisnips'
Plug 'ladislas/vim-snippets'

" YouCompleteMe setup
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_filetype_blacklist={'unite': 1}
let g:ycm_min_num_of_chars_for_completion = 1
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>

" UltiSnips setup
let g:UltiSnipsExpandTrigger='<c-k>'
let g:UltiSnipsJumpForwardTrigger='<c-k>'
let g:UltiSnipsJumpBackwardTrigger='<c-s-k>'
let g:UltiSnipsSnippetsDir=plugDir.'/vim-snippets/UltiSnips'

Hope this helps.