UltiSnips and YouCompleteMe

前端 未结 14 1875
囚心锁ツ
囚心锁ツ 2020-12-07 06:40

I have bundles ultisnips and youcompleteme installed on my macvim. The problem is that ultisnips doesn\'t work because tab is bound by ycm. I tried putting let g:UltiS

相关标签:
14条回答
  • 2020-12-07 07:31

    Another option is using the SuperTab plugin:

    " if you use Vundle, load plugins:
    Bundle 'ervandew/supertab'
    Bundle 'Valloric/YouCompleteMe'
    Bundle 'SirVer/ultisnips'
    
    " make YCM compatible with UltiSnips (using supertab)
    let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
    let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
    let g:SuperTabDefaultCompletionType = '<C-n>'
    
    " better key bindings for UltiSnipsExpandTrigger
    let g:UltiSnipsExpandTrigger = "<tab>"
    let g:UltiSnipsJumpForwardTrigger = "<tab>"
    let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
    

    Here YouCompleteMe is bound to a different combination Ctrln, but then that combination is bound to tab through SuperTab. UltiSnips and SuperTab play nice together, so you can then just bind UltiSnips to tab directly and everything will work out.

    0 讨论(0)
  • 2020-12-07 07:31

    Based on Siegfried's answer, I am using the following which seems more natural:

    let g:ycm_key_list_select_completion = ['<C-j>']
    let g:ycm_key_list_previous_completion = ['<C-k>']
    
    let g:UltiSnipsExpandTrigger = "<C-l>"
    let g:UltiSnipsJumpForwardTrigger = "<C-j>"
    let g:UltiSnipsJumpBackwardTrigger = "<C-k>"
    

    I also use the c-hjkl bindings somewhere else (switching from a pane to another), but that would only be in normal mode, so there's no problem.

    0 讨论(0)
  • 2020-12-07 07:37

    i have this in my vimrc

    "" YouCompleteMe
    let g:ycm_key_list_previous_completion=['<Up>']
    
    "" Ultisnips
    let g:UltiSnipsExpandTrigger="<c-tab>"
    let g:UltiSnipsListSnippets="<c-s-tab>"
    

    thats what i did on my first try, but i misspelled UltiSnips with Ultisnips.. oh well, worked out in the end!

    0 讨论(0)
  • 2020-12-07 07:37

    Although I know this post is a little old, I have my own function that is a little more optimized than the one given above:

    function! g:UltiSnips_Complete()
      call UltiSnips#ExpandSnippetOrJump()
      if g:ulti_expand_or_jump_res == 0
        if pumvisible()
          return "\<C-N>"
        else
          return "\<TAB>"
        endif
      endif
    
      return ""
    endfunction
    

    Of course, if you just keep the settings that Joey Liu provided and then just use this function everything will work just perfectly!

    EDIT: Also, I use another function to increase back-stepping functionality between YouCompleteMe and UltiSnips. I'll show you what I mean:

    function! g:UltiSnips_Reverse()                                                                                               
      call UltiSnips#JumpBackwards()                                                                                              
      if g:ulti_jump_backwards_res == 0        
        return "\<C-P>"                                                                                                           
      endif                                                                                                                       
    
      return ""                                                                                                                   
    endfunction
    

    Then just put this in your .vimrc:

    au BufEnter * exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=g:UltiSnips_Reverse()<cr>"
    

    As well as let g:UltiSnipsJumpBackwardTrigger="<s-tab>" and your set!

    0 讨论(0)
  • 2020-12-07 07:41

    I use both of them together. By default YouCompleteMe binds <Tab> and <Down> to select the next completion item and also <S-Tab> and <Up> to select the previous completion item. You can change the YouCompleteMe bindings with the g:ycm_key_list_select_completion and g:ycm_key_list_previous_completion options. Note that the names of these options were recently changed when the option was changed from a single string to a list of strings.

    0 讨论(0)
  • 2020-12-07 07:43

    I personally chose to not use <tab> with YouCompleteMe but navigate it manually.

    So I added this to my .vimrc:

    let g:ycm_key_list_select_completion=[]
    let g:ycm_key_list_previous_completion=[]
    

    which simply disables the tab key for YCM. Instead you use the movement keys (arrows or CTRL-N/CTRL-P) and select the entry with CR. UltiSnips works default with tab.

    0 讨论(0)
提交回复
热议问题