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

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 **/*.go matches all .go files in subdirectories
  • :args with no argument displays the current list
  • The current file is highlighted in the :args display 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

  • :argdo automatically saves each file if modified (with update), and visits every file even if previous commands had errors (use the e flag on substitutions)
  • Combine with vimgrep for a focused workflow: first narrow with :vimgrep to populate quickfix, then use :cfdo for the actual changes
  • :args # resets the argument list to the current buffer's filename
  • :argdelete * clears the list without closing any buffers

Next

How do I inspect a Vim register's full details including its type (charwise, linewise, or blockwise) in Vimscript?