VimTrick: Replace across files
Use the args list to globally replace across files without plugins
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.
Was this useful? Help us improve!
With your feedback, we can improve VimTricks. Click a link to vote:
There's a typo, should be `:argdo` and not `:argodo`. For my neovim setup running the substitution in separate commands did not work for me, I had to do `:argdo <substitution> | update`. Anyway, thanks for the tip!
Another great content, with some aditional information about arglist is this: http://vimcasts.org/transcripts/41/en/