Remapping tab completions in vim

旧城冷巷雨未停 提交于 2019-12-24 08:28:42

问题


I've got a crazy little challenge. I'd like to remap tab and shift + tab to the basic tab completions in vim. Here's where I started:

set completeopt=
inoremap <tab> <C-n>
inoremap <S-tab> <C-p>

That didn't have any effect at all, and I also realized it might be messing up my snippets plugin. I went googling around and found this: http://vim.wikia.com/wiki/Smart_mapping_for_tab_completion, but had little luck implementing any of the suggestions.

I'd like to map to tab and to shift + tab, without losing snippet functionality. Any help would rock!

Update: I also tried this with now luck. It had no perceivable effect.

fu! InsertTabWrapper(direction)
  let char_before = col('.') - 1
  if !char_before || getline('.')[char_before - 1] !~ '\k'
    return "\<tab>"
  elseif "backward" == a:direction
    return "\<c-p>"
  else
    return "\<c-n>"
  endif
endfu
inoremap <tab> <c-r>=InsertTabWrapper("forward")<cr>
inoremap <s-tab> <c-r>=InsertTabWrapper("backward")<cr>

回答1:


I agree with you that mapping <tab> is a headache thing in vim.

Personally I have SuperTab, Neocompletecache, Snipmate and pydiction.... it really took some time to let them work together, with <tab>... even if not (maybe) perfect, it is enough for my daily usage.

Back to your problem, you could consider to install a plugin called superTab (https://github.com/ervandew/supertab) and in your .vimrc add these lines:

let g:SuperTabDefaultCompletionType = 'context'
let g:SuperTabContextTextOmniPrecedence = ['&omnifunc','&completefunc']
let g:SuperTabRetainCompletionType=2

inoremap <expr><Enter>  pumvisible() ? "\<C-Y>" : "\<Enter>"
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"

then .... good luck... I hope it works for your requirement.



来源:https://stackoverflow.com/questions/15643234/remapping-tab-completions-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!