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

How do I load a set of files matching a glob pattern into Vim's argument list for bulk editing?

Answer

:args **/*.py

Explanation

Vim's argument list (arglist) is a named list of files that you can operate on as a group. Setting it with :args {glob} lets you load exactly the files you want and then use :argdo, :first/:last, ]a/[a, or macros to process every file in the list systematically.

How it works

  • :args {glob} sets the arglist to all files matching the glob
  • **/*.py means "any .py file in any subdirectory" (requires :set wildignore and shell globbing support)
  • After setting the arglist:
    • :args (no argument) shows the current list
    • :first / :last jump to the first or last file
    • ]a / [a cycle through files (with vim-unimpaired), or :next / :prev
    • :argdo {cmd} runs a command on every file
  • :argadd {file} adds individual files to the existing arglist
  • :argdelete {pattern} removes entries

Example

Load all Python files for a project-wide rename:

:args src/**/*.py
:argdo %s/OldClassName/NewClassName/ge | update

Or load files matching multiple patterns:

:args src/**/*.js test/**/*.js

Tips

  • The arglist persists for the session; use :args % to reset it to just the current file
  • Use :args output to double-check the file list before running any :argdo command
  • Vim's glob ** requires :set wildignorecase off and proper shell support; on some systems, supply the list from the shell: :args `find . -name '*.py'`
  • The arglist is separate from the buffer list — files in the arglist that are not open are loaded on demand

Next

How do I run a search and replace only within a visually selected region?