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

How do I insert all possible completions at once on the command line instead of cycling through them?

Answer

<C-a> (in command-line mode)

Explanation

In Vim's command-line mode, pressing <C-a> inserts all possible completions for the current word onto the command line at once. This is different from <Tab> (cycle through one at a time) and <C-d> (list completions without inserting them).

How it works

  • <Tab> — inserts the first completion, then cycles to the next on repeated presses
  • <C-d> — shows a list of all completions but does not insert them
  • <C-a> — immediately inserts all completions as a space-separated list on the command line

The completions offered depend on what you're typing:

  • After :e or :sp — filenames matching the partial name
  • After :b — buffer names
  • After :set — option names
  • After a command expecting multiple arguments — anything Vim can complete for that context

Example

To quickly build a command involving multiple matching files, start typing a glob and press <C-a>:

:e src/*.c<C-a>

This expands to something like:

:e src/foo.c src/bar.c src/baz.c

You can then edit the resulting command before pressing <CR>.

Another useful case — insert all loaded buffer names:

:b <C-a>

Tips

  • Use <C-d> first if you want to preview completions before committing
  • Works in search prompts (/) and input prompts as well as : commands
  • If only one completion matches, <C-a> and <Tab> behave identically

Next

How do I hard-wrap the current paragraph to the textwidth in Vim?