Skip to main content

Find and Replace Across files in Vim

Back-end Development

Here's a simple way to do a find and replace across files in vim: Load all the files you want to edit into vim:

bash Ag "pattern" -l | xargs vim -

Here I'm using Ag, an ack replacement: (https://github.com/ggreer/the_silver_searcher) to get a list of files that contain the text I want to change.

Next, run the following in the newly opened vim window:

bash :argdo %s/pattern/substitution/gce | update

Omit the "c" in the search options if you don't want to confirm each replacement. Happy vimming!

Need a fresh perspective on a tough project?

Let’s talk about how RDG can help.

Contact Us