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 listfull— 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 wildmenumust also be enabled (or usewildoptions=pumin Neovim) for the visual menu to appearwildmode=list:longest,fullis another popular variant: first press lists all options, second fills the longest, third cycles:help 'wildmode'for the complete list of available modes