Replace across files

4.1
(187)

There are many plugins for handling find/and replace across files in Vim, but sometimes only a native way will do. While many people prefer to do substitution from their command line outside of Vim, I often reach for this native, no-plugin way to substitute text across files: the args list.

First, you populate the args list with the list of files you want to search across. For example:

:args path/to/file/glob/*.js

Next, you perform the substitution across those files:

:argdo %s/pattern/replacement/g

Finally, save all the files:

:argdo update

Checkout the gif below where I perform these 3 steps to change all the references of vim to emacs. The gif is too annoying to watch, I’ve uploaded a video version to our YouTube channel.

How useful was this tip?

Average rating 4.1 / 5. Vote count: 187

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

90 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

1 thought on “Replace across files”

Leave a reply

Your email address will not be published. Required fields are marked *