How do I run a recorded macro on every file in my argument list at once?
Answer
:argdo normal @a
Explanation
The :argdo command applies any Ex command to every file in the argument list. Combined with normal @a, it replays a recorded macro across an entire set of files — making multi-file batch edits effortless without writing a script.
How it works
:argdoiterates through all files in the argument list (set via:argsor files passed on startup)normal @aexecutes the macro in registeraas if typed in Normal mode- Vim opens each file, runs the macro, and advances to the next
- Append
| updateto automatically save each modified file
Example
Suppose you want to strip trailing semicolons from every Go file:
" Set the argument list to all Go files
:args **/*.go
" Record a macro in register q
qq0$x:s/;$//e<CR>q
" Apply to all files and save
:argdo execute 'normal @q' | update
Tips
- Run
:set hiddenfirst so Vim allows switching buffers with unsaved changes - Use
:bufdo normal @aif the files are already open in buffers instead of the arg list - Prefer
:argdo execute 'normal @a'over:argdo normal @ain scripts —executeproperly surfaces errors per file - Combine with
:vimgrepto build a targeted arg list::vimgrep /TODO/ **/*.md | copenthen:cfdo normal @a | updateto act only on matched files