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**/*.pymeans "any.pyfile in any subdirectory" (requires:set wildignoreand shell globbing support)- After setting the arglist:
:args(no argument) shows the current list:first/:lastjump to the first or last file]a/[acycle 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
:argsoutput to double-check the file list before running any:argdocommand - Vim's glob
**requires:set wildignorecaseoff 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