How to Use VIM to Search and Replace Text Across Multiple Files

Recently found out my apps aren’t working due to FactoryGirl changes. I’ve honestly felt more comfortable using Textmate until I tried its find and replace feature. It totally works but it is so slow.

VIM is a lot faster.

This is what I did to replace Factory( with FactoryGirl.create

cd features/step_definitions/

To open all files within step_definitions directory:

vim -p *  

To make sure changes will be written to all files open:

:set autowriteall

:bufdo %s/Factory(/FactoryGirl.create(/ge

There’s probably an easier way to say that. Be careful about using autowrite. I think there are cases wherein changing every file is better.

Of course those Windows users using Agent Ransack will probably LOL.

The VIM documentation offers a better explanation about the commands.

Read: Run a command in multiple buffers