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

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 / :prev to step through, or :argdo to 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 **/*.ts appends more files to an existing arglist without replacing it
  • :argdelete {pattern} removes matching files from the list
  • :first / :last jump to the start or end of the arglist
  • Combine with :grep results: :args \ grep -l 'TODO' **/*.py (shell expansion) to load only files containing a pattern
  • The arglist survives across :next / :prev navigation, unlike buffer lists which accumulate everything you open

Next

How do I refer to the matched text in a Vim substitution replacement?