How do I configure Vim's command-line completion to first expand to the longest match, then show a list?
Answer
set wildmode=longest:list,full
Explanation
Setting wildmode=longest:list,full gives Vim a completion behavior similar to shells like bash and zsh. The first Tab press expands the command-line input to the longest unambiguous prefix and simultaneously shows all matches below the command line. A second Tab cycles through each match individually. This is ideal for file completion and Ex command completion in busy projects.
How it works
wildmode is a comma-separated list of modes, each applying to successive Tab presses:
longest— expand to the longest common prefix of all matches (like bash)list— after expanding, show all matches in a horizontal list below the command linefull— on the next Tab, cycle through each match one at a time
So with longest:list,full:
- Tab 1: expand the longest match AND show the list
- Tab 2+: step through each individual match
Example
With this setting active, typing :e src/c<Tab> in a project with src/client.go, src/config.go, and src/cache.go would expand to :e src/c (the common prefix), then display the three candidates below the command line. A second <Tab> would complete to src/cache.go, the next <Tab> to src/client.go, and so on.
Tips
- Pair this with
set wildmenu(which enables the visual wildmenu bar) for the best experience set wildmode=fullalone (Vim default forwildmenu) immediately starts cycling without showing the longest prefix — less useful in large projects- In Neovim,
set wildoptions=pumrenders the list in a floating popup instead of the statusline area, compatible with anywildmodesetting - Add
set wildignore+=*.o,*.pyc,node_modules/**to skip uninteresting files during completion