IT박스

UltiSnips와 YouCompleteMe

itboxs 2020. 7. 8. 08:07
반응형

UltiSnips와 YouCompleteMe


Macvim에 번들 ultisnips 및 youcompleteme가 설치되어 있습니다. 문제는 탭이 ycm에 의해 묶여 있기 때문에 ultisnips가 작동하지 않는다는 것입니다. let g:UltiSnipsExpandTrigger = "<s-tab>"shift-tab으로 스 니펫 완료를 트리거 할 수 있도록 넣어 보았지만 알 수없는 이유로 작동하지 않습니다. 나는 뚜껑을 방아쇠로 사용할 수는 있지만 지금까지는 그렇게 할 수있는 방법을 찾지 못했습니다.

이 두 애드온을 함께 사용하는 사람이 있습니까? Shift-Tab을 작동 시키려면 어떻게해야합니까? 스 니펫을 트리거하기 위해 다른 키를 추천 할 수 있습니까?


또 다른 옵션은 SuperTab 플러그인을 사용하는 것입니다.

" 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>"

여기서 YouCompleteMe는 다른 조합에 바인딩되어 Ctrln있지만 해당 조합은 SuperTab을 통해 탭에 바인딩됩니다. UltiSnips와 SuperTab은 함께 잘 작동하므로 UltiSnips를 탭에 직접 바인딩하면 모든 것이 잘됩니다.


YouCompleteMe 이슈 트래커 페이지 에서이 제안을 시도하십시오 . .vimrc에서 :

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

이 설정은 스 니펫 공유를 스 니펫 내에서 앞으로 건너 뛰기 위한 기본 매핑으로 확장하지만 UltiSnips 도움말 태그에 언급 된대로 TextMates의 동작을 시뮬레이션합니다.

Caps Lock 키를 Ctrl에 매핑 했으므로이 매핑은 매우 매끄럽게 작동합니다.


다음 코드를 vimrc에 복사하고 즐기십시오. 이 기능은 YCM과 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>"

나는 내 vimrc 에이

"" YouCompleteMe
let g:ycm_key_list_previous_completion=['<Up>']

"" Ultisnips
let g:UltiSnipsExpandTrigger="<c-tab>"
let g:UltiSnipsListSnippets="<c-s-tab>"

그게 내가 첫 번째 시도에서 한 일이지만 Ultisnips로 UltiSnips의 철자를 잘못 입력했습니다.


개인적 <tab>으로 YouCompleteMe와 함께 사용하지 않고 수동으로 탐색했습니다.

그래서 나는 이것을 내 추가했다 .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.


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!


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.


Just putting together answers by Michaelslec, Joey Liu and along with solutions I found in this issue thread and this guy's vimrc, I now have this which solved pretty much all problems.

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

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

  return ""
endfunction


if !exists("g:UltiSnipsJumpForwardTrigger")
  let g:UltiSnipsJumpForwardTrigger = "<tab>"
endif

if !exists("g:UltiSnipsJumpBackwardTrigger")
  let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
endif

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

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.


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.


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.


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.


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.

참고URL : https://stackoverflow.com/questions/14896327/ultisnips-and-youcompleteme

반응형