How do I run a substitution across all files in the argument list?
Answer
:argdo %s/old/new/g | update
Explanation
The :argdo command runs an Ex command on every file in the argument list (the files you opened Vim with, or added via :argadd). Combined with :update (which saves only if changed), it enables project-wide find-and-replace without plugins.
How it works
:args **/*.pysets the argument list to all Python files recursively:argdo %s/old/new/g | updateruns the substitution on each file and saves| updatesaves only files that were actually modified- Without
| update, changes stay unsaved in buffers
Example
Rename a function across all JavaScript files:
:args **/*.js
:argdo %s/getData/fetchData/ge | update
The e flag suppresses errors for files that don't contain the pattern, so the command continues through all files.
Tips
- Use
:argswith no arguments to see the current argument list - Add files with
:argadd *.txtor set a new list with:args **/*.go - Combine with
:argdoand any Ex command, not just substitutions::argdo normal @a | updateruns a macro on every file - For quickfix-based results (from
:vimgrep), use:cfdoinstead — it operates only on files that had matches