Replace across files


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.3 / 5. Vote count: 269

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

105 Posts

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