How do I populate the argument list with a glob pattern to work across multiple files?
Answer
:args {pattern}
Explanation
The :args command sets Vim's argument list to all files matching a glob pattern. The argument list acts as a named, ordered collection of files you can iterate with :next, :prev, :first, :last, and batch-process with :argdo.
How it works
:args {pattern}— replaces the current argument list with matching files- Supports
**for recursive globbing::args **/*.gomatches all.gofiles in subdirectories :argswith no argument displays the current list- The current file is highlighted in the
:argsdisplay with[brackets]
Example
:args **/*.md
:args
Output might look like:
[README.md] docs/install.md docs/usage.md CHANGELOG.md
Then use :argdo to run a command on all files:
:argdo %s/oldname/newname/ge | update
Tips
:argdoautomatically saves each file if modified (withupdate), and visits every file even if previous commands had errors (use theeflag on substitutions)- Combine with
vimgrepfor a focused workflow: first narrow with:vimgrepto populate quickfix, then use:cfdofor the actual changes :args #resets the argument list to the current buffer's filename:argdelete *clears the list without closing any buffers