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-linelongest— complete to the longest common prefix of all matches (stops when it can go no further)full— cycle through each match one at a timelist:longest— on the same Tab press, both show the list and complete the longest prefixlastused— 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
wildmenufor an inline highlighted completion menu::set wildmenu - Use
wildignoreto exclude noisy files::set wildignore=*.o,*.pyc,node_modules/ - Neovim users can add
:set wildoptions=fuzzyfor fuzzy matching across all completions - The classic "sensible" combo for
.vimrc:set wildmenu set wildmode=list:longest,full