From within Vim, you can search all files for a string/pattern with the following ex command.
Replace “string_to_find” with your search string. The path given as example is every file under the app directory recursively.
:vimgrep /string_to_find/ ./app/**/*
That command will put all occurances of the string into your quickfix list.
You can then run a command on each instance of that with the following command:
:cdo s/string_to_find/new_string/gc
This runs a substitution for each entry in the quickfix list.
The `g` flag is “global” which means if the occurance happens multiple times on the same line it will replace all. Otherwise it will only replace the first instance on each line.
The `c` flag is to “confirm” each change. Each change it tries to make, it will ask you to specifically answer yes or no to change it. I prefer this for most things.
You can then either manually write each file you have changed, or use the following command to save all the files that have been changed:
:cdo update
Leave a Reply