How do I refer to all files in the argument list at once in an Ex command?
Answer
##
Explanation
The ## special token expands to the names of all files currently in Vim's argument list. Just as % expands to the current filename, ## expands to the entire argument list, letting you pass all those files to any Ex command that accepts filenames.
How it works
:args *.goor:args **/*.jsloads files into the argument list##in any subsequent Ex command expands to that full list of filenames- Useful with commands like
:vimgrep,:grep, and:argdothat operate on multiple files
Example
Load all Python files in the project:
:args **/*.py
Now search across all of them with one command:
:vimgrep /def main/ ##
This is equivalent to typing every filename explicitly but works dynamically as your arglist changes. To view which files are in the argument list:
:args
To run an external grep across all arglist files:
:grep -n 'TODO' ##
Tips
##always reflects the current argument list at the time the command runs- Combine with
:argdofor operations that need to run commands per-file::argdo %s/old/new/g | update - For single-file reference use
%(current file) or#(alternate file) - Use
:nextand:prevto navigate the argument list one file at a time