Vim Apply Macro To All Open Buffers Link to heading
Apply a macro to multiple files
" run macro in `q` register to all buffers in normal mode
:bufdo norm @q
- Open all the files as buffers in Vim, for example with:
fd md ~/myproject | xargs nvim
- Record macro in some register, typically
q
- Run
:bufdo norm @q
- Write buffers
:wa
You can also execute and write in one command, though I generally don’t find the need to do this:
:bufdo execute "norm @q" | write
[!tip] A good principle is to avoid motions in macros, and only handle the text editing, since you have means like this and [[vim-apply-macro-to-multiple-lines|applying macro to multiple lines]] to reuse the macro in multiple places.