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

How do I configure Vim's command-line tab completion to show a list of matches?

Answer

:set wildmode=longest,list

Explanation

By default, Vim's command-line <Tab> completion just cycles through matches one at a time. Setting wildmode changes this behavior to feel more like Bash or Zsh shell completion — showing a full list and completing to the longest common prefix first.

How it works

wildmode accepts a comma-separated list of up to four phases, applied in order:

  • longest — complete to the longest common prefix shared by all matches
  • list — show a list of all matches below the command line
  • full — complete to the next full match (classic Vim behavior)
  • lastused — (Neovim) prefer recently used matches first

With :set wildmode=longest,list, the first <Tab> expands the longest prefix, and a second <Tab> opens the match list.

Example

With a directory containing README.md, routes.lua, and run.sh, typing:

:e r<Tab>

Expands to :e r (longest common prefix is r), then a second <Tab> shows:

README.md  routes.lua  run.sh

A popular Neovim alternative is:

:set wildmode=longest:full,full

This uses wildmenu (see below) for an inline match bar.

Tips

  • Pair with :set wildmenu to display matches in the status bar as an interactive menu
  • :set wildignore+=*.o,*.class,node_modules/** excludes uninteresting files from completion
  • The wildoptions=pum setting (Neovim 0.6+) renders matches in a floating popup instead of the status line

Next

How do I get just the filename without its path or extension to use in a command?