vimtricks.wiki Concise Vim tricks, one at a time.

How do I configure command-line tab completion to show the longest match first then cycle?

Answer

:set wildmode=longest:full,full

Explanation

The wildmode option controls what happens when you press <Tab> in the command line. Setting it to longest:full,full gives you a two-stage completion experience that many users find optimal: the first <Tab> fills in as much as possible and opens the wildmenu, and subsequent <Tab> presses cycle through individual matches.

How it works

wildmode is a comma-separated list where each entry describes what a successive <Tab> press does:

  • longest:full — first press: complete to the longest common prefix and display the wildmenu list
  • full — subsequent presses: cycle through each full match one at a time

This mirrors how Bash completion behaves: you get the unambiguous part filled in for free, see all options, then tab through them.

Example

:set wildmode=longest:full,full
:set wildmenu

" Type :e buf<Tab>
" → fills in ':e buffer' (longest common prefix) and shows wildmenu
" → press <Tab> again to cycle: buffer1, buffer2, buffer3...

Without this setting, Vim's default wildmode=full jumps straight to cycling from the first <Tab> press, which can skip past the best match.

Tips

  • :set wildmenu must also be enabled (or use wildoptions=pum in Neovim) for the visual menu to appear
  • wildmode=list:longest,full is another popular variant: first press lists all options, second fills the longest, third cycles
  • :help 'wildmode' for the complete list of available modes

Next

How do I enable matchit so % jumps between if/else/end style pairs?