App-Wide Search-Replace in Vim
- In command-line mode, load all desired files into your argument list (arglist)
:args `git grep -l <string>`
where <string>
is the string you want to replace.
- Run a global search-replace across all the files in your arglist
:argdo %s/<string>/<replacement>/gce | update
Note:
-
Search-replace flags:
- g[lobal]: replace all matches
- c[onfirm]: ask for confirmation before replacing
- e[rror]: don't halt operation at errors
-
update
saves each file after the replacement is made. -
The search-replace will only apply to files checked into your git history. Be sure to commit the files you want searched before attempting this.