How do I load multiple files matching a pattern into Vim for batch editing?
Answer
:args **/*.js
Explanation
The :args command populates Vim's argument list with files matching a glob pattern, turning any set of files into a navigable list and enabling project-wide batch operations. This is the prerequisite step for powerful commands like :argdo, :next, and :prev.
How it works
:args {glob}replaces the current argument list with all matching files**is a recursive glob — it descends into subdirectories- After setting the arglist, Vim opens the first file automatically
- Use
:next/:prevto step through, or:argdoto run a command on all of them
Example
Load all JavaScript files in the project:
:args **/*.js
Then apply a substitution across every file and save:
:argdo %s/require('lodash')/require('lodash-es')/ge | update
Or view which files are in the list with their indices:
:args
Tips
:argadd **/*.tsappends more files to an existing arglist without replacing it:argdelete {pattern}removes matching files from the list:first/:lastjump to the start or end of the arglist- Combine with
:grepresults::args\grep -l 'TODO' **/*.py(shell expansion) to load only files containing a pattern - The arglist survives across
:next/:prevnavigation, unlike buffer lists which accumulate everything you open