October 2, 2008
Vim: Substitute in all buffers
To replace all instances of FOO with BAR in one file, you’d do:
:%s/FOO/BAR/g|:up
The pipe | lets you separate multiple commands and :up is like :w but only writes changed buffers.
Now for all open files:
:bufdo :%s/FOO/BAR/g|:up
Roughly translates to: for all open buffers, substitute FOO with BAR and write the changes.
Comments(3)
You may want to use :up[date] instead of :w[rite] so you only save files that are actually modified. this is how :wa[ll] works.
Proves I don’t know a whole lot of Vim commands! :)
I updated the original text to use :up.
Thanks!
Great tip, thanks!