Word / Code Completion in VIM

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:11:30

问题


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.

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>

After I type te in the 2nd line, the popup should suggest test, teter and 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<TAB>
    • should do nothing because "we" don't know if a 't' (teter) or an 's' (test, testor) should follow.
  • tes<TAB>
    • should expand to test (because that works for both - test and testor - and teter is no longer a possible match).
  • test<TAB>
    • should expand to testor (only possible match).

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.


回答1:


:set completeopt=longest,menu,preview

maybe?

(I'm not sure if your statement

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

conflicts with your later statement

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



来源:https://stackoverflow.com/questions/1055084/word-code-completion-in-vim

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