Vim: multi-file replace `:%s`
So you wanna run vim’s s
command on multiple files.
I gotchu.
-
Open all files you want to replace as buffers
:e test/*
-
Run the command on all files and update the content
:bufdo %s/heading/root_text/g | update
-
Don’t forget to overwrite if you are satisfied with the results
:bufdo w
Done! Note that this is not just limited to replacing. It applies to any command, or set of commands.
If you already have some buffers open and you’d rather make a new list of files, you can replace:
e
withargs
bufdo
withargdo
.