VIM 中的字/代码补全 [英] Word / Code Completion in VIM

查看:19
本文介绍了VIM 中的字/代码补全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过 CTRL+N & 来完成单词的补全CTRL+P 和使用 CTRL+X CTRL+O 通过 omnifunc 完成代码.我还尝试了 Supertab(非常好),因为我习惯了 TAB 完成.一切正常.我想在打字时看到可能的匹配项,所以我也尝试了 autocomplpop.vim,女巫就是这么做的.

I know that I can get word completion through CTRL+N & CTRL+P and code completion through omnifunc with CTRL+X CTRL+O. I additionally tried Supertab (very nice), because I'm used to TAB-completion. That all worked all right. I would like to see possible matches while I'm typing, so I also tried autocomplpop.vim, witch does just that.

不过,我喜欢完成的是将两者结合起来并稍加改动:我希望在我输入时看到建议弹出(就像使用 autocompop 一样)但是当我使用TAB 这个词应该扩展到最大的共同匹配:

What I like to accomplish though, would be a combination of both together with a little twist: I would like to see suggestions pop up as I type (just like with autocompop) but when I use TAB the word should be expanded only to the largest common match:

foo bar testor booze test baz teter
te<TAB>

在我在第二行输入 te 后,弹出窗口应该提示 testtetertestor.

After I type te in the 2nd line, the popup should suggest test, teter and testor.

当我按下 TAB 时,它应该什么都不做,因为没有比 te 更通用的地方了.在我输入额外的 s 并按 TAB 后,它应该将 tes 扩展为 test(因为它是最小的共同点)并在第二个 TAB 之后到 testor.

When I press TAB, it should do nothing, because there is no more common ground than te. After I typed an additional s and press TAB, it should expand tes to test (because it is the smallest common ground) and to testor after a 2nd TAB.

编辑:我尽量说得更清楚...

Edit: I try to be more clear...

  • te
    • 什么都不做,因为我们"不知道是t"(teter)还是s"(test, testor) 应该遵循.
    • te<TAB>
      • should do nothing because "we" don't know if a 't' (teter) or an 's' (test, testor) should follow.
      • 应该扩展为 test (因为这对测试和测试者都有效 - 并且 teter 不再是可能的匹配项).
      • should expand to test (because that works for both - test and testor - and teter is no longer a possible match).
      • 应扩展为 testor(仅可能匹配).
      • should expand to testor (only possible match).

      好吧,建议弹出窗口只是奖励,但我真的很想看到 TAB 行为.希望我不会在这里变得深奥,你可以帮助我使用一些脚本技巧或插件来驯服 VIM 来做到这一点.

      Well, the suggestions popup is just bonus, but I really would love to see the TAB behavior. Hope I don't get to esoteric here and you can help me out with some script-tricks or plugins to tame VIM to do just that.

      推荐答案

      :set completeopt=longest,menu,preview
      

      也许?

      (我不确定你的说法是否

      (I'm not sure if your statement

      当我按下 TAB 时,它应该什么都不做,因为没有比 te 更通用的地方了"

      "when I press TAB, it should do nothing, because there is no more common ground than te"

      与你后来的陈述相冲突

      在第二个 TAB 之后测试人员."

      "to testor after a 2nd TAB."

      在我看来,此时没有比测试"更通用的地方了……除非您的意思是第一个选项卡进入最长的共同点,然后后续选项卡在其他匹配项中循环,在这种情况下你在追求我上面的东西......)

      It seems to me that there's no more common ground than "test" at that point... Unless you mean the first tab goes to the longest common ground, and then the subsequent tabs cycle through the other matches, in which case you're after what I have above...)

      这篇关于VIM 中的字/代码补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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