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

How do I configure Vim's command-line tab completion to show all matches and complete to the longest common prefix?

Answer

:set wildmode=list:longest

Explanation

Vim's wildmode option controls how the command line behaves when you press <Tab> to complete filenames, buffer names, or Ex commands. The default full mode cycles through completions one at a time — which can be tedious when there are many matches. Setting wildmode=list:longest instead shows all matches in a list and immediately completes to the longest unambiguous prefix, mimicking bash/zsh tab-completion behavior.

How it works

wildmode accepts a comma-separated list of up to four modes for successive <Tab> presses:

  • full — complete to the next full match (default cycling)
  • longest — complete to the longest common prefix
  • list — list all matches without completing
  • list:longest — list all matches and complete to the longest prefix on the first <Tab>

Setting :set wildmode=list:longest means:

  • First <Tab> → list all matches + complete to the longest prefix
  • Additional <Tab> presses → no further cycling

A popular two-stage alternative is :set wildmode=list:longest,full, which lists matches on the first <Tab>, then cycles through them one by one.

Example

With wildmode=full (default), typing :e Do<Tab> cycles: Documents/, Downloads/, Documents/...

With wildmode=list:longest, typing :e Do<Tab> shows:

Documents/  Downloads/

And completes to :e Do (the longest prefix), letting you type more characters to disambiguate.

Tips

  • Pair with :set wildmenu to show the completion list in the status bar (enabled in modern Vim by default)
  • :set wildignore+=*.pyc,node_modules/** excludes clutter from completions
  • In Neovim, wildmode=longest:full,full with wildoptions=pum enables a popup completion menu
  • Add to your vimrc: set wildmode=list:longest,full

Next

How do I see a summary of all previous quickfix lists from my current session and navigate between them?