The general workflow is:
- Search for your pattern across the project.
- Operate on each match (safer, slower) or on each file with matches (riskier, faster).
- Write your changes.
The first step can be done with any command that populates the quickfix list: :help :vimgrep, :help :grep, something from a third-party plugin, etc.
Taking :grep as an example:
:grep foo **/*.js
will populate the quickfix list with an entry for every foo found in *.js files in the current directory and subcategories. You can see the list with :cwindow.
The second step involves :help :cdo or :help :cfdo:
:cdo s/foo/bar/gc
which will substitute every foo with bar on each line in the quickfix list and ask for confirmation. With :cfdo it would look like that:
:cfdo %s/foo/bar/gc
If you are super confident, you can drop the c at the end. See :help :s_flags.
The third step involves :help :update:
:cfdo update
which will write every file in the quickfix list to disk if they have been changed.
In short:
:gr foo **/*.js
:cdo s/foo/bar/gc
:cfdo up
:bufdoas well. You can start with:set awa(all write all) which will save all changed files without interrupting the process and then:bufdo %s/<match-string>/<replace-string>/gewhich will replace multiple occurrences on all lines and keep going even on errors (no match found).