重新映射Vim中的制表符补全 [英] Remapping tab completions in vim

查看:147
本文介绍了重新映射Vim中的制表符补全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个疯狂的小挑战.我想重新映射制表符,然后将+制表符转换为vim中的基本制表符补全.这是我开始的地方:

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>

那根本没有任何作用,我也意识到这可能会弄乱我的代码片段插件.我四处搜寻,发现了以下内容: http://vim.wikia.com/wiki/Smart_mapping_for_tab_completion ,但实施任何建议的运气都不太好.

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>

推荐答案

我同意您的观点,映射<tab>是vim中令人头疼的事情.

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

我个人有 SuperTab Neocompletecache Snipmate pydiction ....确实需要一些时间.为了让他们与 <tab> 一起工作,即使不是(也许)完美,也足以满足我的日常使用需求.

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.

回到问题所在,您可以考虑安装名为superTab的插件( https://github.com/ervandew/supertab ),然后在您的.vimrc中添加以下行:

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.

这篇关于重新映射Vim中的制表符补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆