Word / Code Completion in VIM

code-completion, vim

Solution

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

Problem

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.

Original source