Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word / Code Completion in 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.

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.

like image 843
Brutus Avatar asked Jun 28 '09 15:06

Brutus


People also ask

Does Vim support code completion?

Vim editor supports Autocomplete by default for the standard text files and enables autocomplete for programmatic files by explicit configuration.

Can you get Intellisense in Vim?

The auto-completion system (Intellisense) in VSCode is arguably its best feature. Lucky for us, it's been ported over to Vim!

How do you make a completion code?

Press Ctrl+Alt+S to open the IDE settings and select Editor | General | Code Completion. Under Machine Learning-Assisted Completion, enable the Sort completion suggestions based on machine learning option, and select the languages for which you want to use ML completion.


1 Answers

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

like image 156
Stobor Avatar answered Nov 16 '22 02:11

Stobor