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

How do I configure command-line Tab completion to show a list and complete the longest common match first?

Answer

:set wildmode=list:longest,full

Explanation

Vim's default Tab completion in the command-line cycles through matches one at a time, making it hard to see all available options at once. The wildmode option controls the exact behavior of each Tab press, letting you replicate the ergonomic shell-style workflow: first Tab shows all matches and completes as far as possible, second Tab cycles through them individually.

How it works

wildmode is a comma-separated list where each entry describes one Tab press phase:

  • list — display all matches in a list below the command-line
  • longest — complete to the longest common prefix of all matches (stops when it can go no further)
  • full — cycle through each match one at a time
  • list:longest — on the same Tab press, both show the list and complete the longest prefix
  • lastused — when cycling buffers, prefer the most recently used

With :set wildmode=list:longest,full:

  • First Tab: shows the match list + completes to the longest unambiguous prefix
  • Second Tab (and beyond): cycles through each match in turn

Example

Typing :e doc<Tab> when doc/, docs/, and docker-compose.yml all exist:

First Tab:  :e doc     → :e doc   (longest prefix) + shows list:
  doc/  docs/  docker-compose.yml
Second Tab: cycles → :e doc/
Third Tab:  → :e docs/

Tips

  • Pair with wildmenu for an inline highlighted completion menu: :set wildmenu
  • Use wildignore to exclude noisy files: :set wildignore=*.o,*.pyc,node_modules/
  • Neovim users can add :set wildoptions=fuzzy for fuzzy matching across all completions
  • The classic "sensible" combo for .vimrc:
    set wildmenu
    set wildmode=list:longest,full
    

Next

How do I permanently add a word to my personal spell file so Vim stops marking it as misspelled?