UltiSnips and YouCompleteMe

前端 未结 14 1887
囚心锁ツ
囚心锁ツ 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:19

    While Many answer works fine in this post, I just want to say that the problem is caused by key binding collision between YCM and UltiSnip, while YCM support UltiSnip snippets by default, it takes the default UltiSnip expand trigger <tab> as its completion select key, so UltiSnip snippets will not be expaned by <tab>. Give them different key binding will solve the problem, I personally use <c-n and <c-p> for YCM and use the default <tab> for UltiSnip. You can get more details with help youcompleteme doc in vim.

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

    Try this suggestion on a page from the YouCompleteMe issue tracker. In your .vimrc:

    let g:UltiSnipsExpandTrigger="<c-j>"
    

    While this setting will make expanding a snippet share the default mapping for jumping forward within a snippet, it simulates TextMates' behavior as mentioned in the UltiSnips help tags.

    Since I've mapped my Caps Lock key to Ctrl, this mapping works pretty smoothly.

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

    I installed the UltiSnips plugin after the YouCompleteMe plugin so I thought they were conflicting, but in reality I had something more interfering:

    set paste
    

    Make sure to remove that from .vimrc if it's present.

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

    copy the following code to your vimrc, and enjoy. This function will handle all issues between YCM and UltiSnips.

    function! g:UltiSnips_Complete()
        call UltiSnips#ExpandSnippet()
        if g:ulti_expand_res == 0
            if pumvisible()
                return "\<C-n>"
            else
                call UltiSnips#JumpForwards()
                if g:ulti_jump_forwards_res == 0
                   return "\<TAB>"
                endif
            endif
        endif
        return ""
    endfunction
    
    au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
    let g:UltiSnipsJumpForwardTrigger="<tab>"
    let g:UltiSnipsListSnippets="<c-e>"
    " this mapping Enter key to <C-y> to chose the current highlight item 
    " and close the selection list, same as other IDEs.
    " CONFLICT with some plugins like tpope/Endwise
    inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
    
    0 讨论(0)
  • 2020-12-07 07:28

    As mentioned by others, mapping C-j to ultisnips works great.
    let g:UltiSnipsExpandTrigger="<c-j>"

    Now, if you go a bit further and install xcape and use
    xcape -e "Shift_L=Control_R|J"

    You unleash the power of using just the shift key for utlitsnips.

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

    I use kj. This is what is in my .vimrc:

    let g:UltisnipsExpandTrigger="kj".

    It rarely happens that I run into word that has kj in it. If this is the case I would just wait a couple of seconds after typing k and that type j.

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