Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: search replace over all writable buffers

Tags:

replace

vim

so

1GvG:s/..../g

can replace over an entire buffer

However, suppose I have multiple vim buffers loaded, and I want to do a :s over all the buffers that are writable; is there a way to do this in vim?

like image 294
anon Avatar asked Mar 15 '10 07:03

anon


2 Answers

Since I can't leave comments, I'll be repeating what Brian said and adding in my 2 cents.

I believe the command you're looking for is:

:bufdo :%s/..../g | :w

Note: This will write each file after the changes are made, so make sure you're ready for this.

If autowrite is on, you should be able to remove the "| :w" at the end of the command.

like image 133
Curt Nelson Avatar answered Sep 18 '22 17:09

Curt Nelson


Take a look at bufdo. There's also windo and tabdo. Keep in mind that per default Vim doesn't autowrite so for search/replace commands across buffer you need to turn on autowrite.

like image 35
Brian Rasmussen Avatar answered Sep 19 '22 17:09

Brian Rasmussen