How do I insert all completion matches at once on the command line instead of cycling through them one by one?
Answer
<C-a> (command-line mode)
Explanation
In command-line mode, <C-a> inserts all completions for the word before the cursor at once, as a space-separated list. This is useful when you want to batch-operate on multiple files or buffers that share a pattern — without manually typing or cycling through each one with <Tab>.
How it works
<Tab>— cycles through completions one at a time, replacing the current word<C-d>— lists completions below the command line without inserting them<C-a>— inserts all completions into the command line simultaneously
Example
To close all JavaScript buffers at once:
:bdelete *.js<C-a>
After pressing <C-a>, Vim expands to something like:
:bdelete app.js utils.js router.js
Press <CR> to close them all in one shot.
Similarly, to quickly diff all modified files:
:diffsplit *.patch<C-a>
Tips
- Works with any command that supports filename or name completion:
:edit,:buffer,:source, etc. - If the list is too long, you can edit it after expansion —
<C-w>to delete words, or<C-u>to clear the line - Pair with wildcards:
:bd test_*<C-a>closes all buffers starting withtest_ - Use
<C-d>first to preview the list, then<C-a>to actually insert it