UltiSnips and YouCompleteMe

2019-01-29 15:33发布

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:UltiSnipsExpandTrigger = "<s-tab>" so that I can trigger the snippet completion with shift-tab, but it doesn't work for some unknown reason. I could use caps as the trigger, but so far I've found no way to do that.

Do any of you use those two add-ons together? What can I do to make shift-tab work? Can you recommend another key to trigger snippets?

12条回答
看我几分像从前
2楼-- · 2019-01-29 15:41

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-29 15:41

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.

查看更多
Luminary・发光体
4楼-- · 2019-01-29 15:42

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!

查看更多
贼婆χ
5楼-- · 2019-01-29 15:45

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.

查看更多
爷的心禁止访问
6楼-- · 2019-01-29 15:53

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.

查看更多
Bombasti
7楼-- · 2019-01-29 16:00

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 and select the entry with CR. UltiSnips works default with tab.

查看更多
登录 后发表回答