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

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 **/*.py sets the argument list to all Python files recursively
  • :argdo %s/old/new/g | update runs the substitution on each file and saves
  • | update saves 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 :args with no arguments to see the current argument list
  • Add files with :argadd *.txt or set a new list with :args **/*.go
  • Combine with :argdo and any Ex command, not just substitutions: :argdo normal @a | update runs a macro on every file
  • For quickfix-based results (from :vimgrep), use :cfdo instead — it operates only on files that had matches

Next

How do I return to normal mode from absolutely any mode in Vim?