0

When I press tab for autocompletion (with the supertab plugin, but its applicable with vim's autocomplete feature as well), the selection scrolls from the bottom-most selection towards top with the selection text being replaced under the cursor. Is it possible to prevent replacing the text under the cursor, maybe my preventing scrolling even if I press tab multiple times.
In the end, the behaviour would be same as how bash works.. You keep typing and pressing tab until you get the required word. No scrolling through the suggestions.

EDIT
The behaviour would be similar to:

set completeopt=longest

but with a menu only for previewing the suggestions.
The one below allows it for just the first tab. Another tab starts scrolling through the menu. The behaviour I expect is to show a menu only for showing suggestions, no scrolling.

set completeopt=longest,menu,noselect

Why do I require this behaviour? Say, these are the available words:

Foo
FooBarBar
FooBarFoo

I intend to write FooBarFoo. I type F<tab>. With set completeopt=longest,menu,noselect, it autocompletes to Foo and show the menu with the remaining suggestions. Now I type FooB<tab> and it starts scrolling and autocompletes to one of the suggestions. Here, I expect it to again complete to the longest word FooBar and show valid suggestions.

0
0

I don't use Supertab but that sounds similar to Vim's 'wildmode' setting "longest". In the Supertab docs there's a global configuration variable that seems related: g:SuperTabLongestEnhanced.

If you enable it with

:let g:SuperTabLongestEnhanced = 1

...then according to :h g:SuperTabLongestEnhanced...

supertab will provide an enhanced longest match support where typing one or more letters and hitting tab again while in a completion mode will complete the longest common match using the new text in the buffer.

The documentation continues with this example where your buffer has the following contents:

FooBarFoo
FooBar
Foo
FooBarBaz

Type F<tab>. Vim's builtin longest support will complete the longest common text 'Foo' and offer 'FooBarFoo', 'FooBar', 'Foo', and 'FooBarBaz' as possible completions.

With supertab's longest match enhancement disabled, typing B<tab> while still in the completion mode will end up completing 'FooBarBaz' or 'FooBarFoo' depending your settings, instead of the next longest common match of 'FooBar'. With supertab's enhanced longest match feature enabled, the typing of B<tab> will result in the next longest text being completed.

If you use this you might also want to look at the help for the related setting g:SuperTabLongestHighlight

5
  • Hey! I have added more context to the question. Please do check. Thanks. Jun 15 at 9:49
  • 1
    And yes, the vim behaviour would be similar to set wildmode=longest,list. Jun 15 at 9:51
  • @subtleseeker Now I'm just confused. You're not talking about supertab at all? Are you talking about autocomplete in a buffer or completion from the command-line?
    – B Layer
    Jun 16 at 2:14
  • @B Layer Supertab seems to use the same completeopt feature of vim. I just removed "supertab" from title to broaden the scope of the question. Its valid for both supertab as well as vim's autocomplete in general. Jun 16 at 6:21
  • The configuration option I describe in my answer extends Vim's functionality in the plugin. Maybe you should make a feature request with that plugin for the functionality you seek. I don't know what the effort would be...looking at the plugin code might help. Will check it out, time permiitting.
    – B Layer
    Jun 16 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.