November 10, 2016

Find and Replace Across files in Vim

Written by

Share on LinkedIn

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:

Ag "pattern" -l | xargs vim -

Here I'm using Ag, an ack replacement: to get a list of files that contain the text I want to change.

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

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

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

Happy vimming!

We'd love to chat about your next web or application project!