Changing Every File at Once

The pattern

:vimgrep /old_name/ **/*.py
:cdo s/old_name/new_name/g | update
  • :cdo runs the command on every entry in the quickfix list
  • | update writes each file, but only if it changed

Because you build the list first, you can open it with :copen and read exactly what is about to change before running the substitute. That is the difference between this and a blind sed -i across the tree.

:cfdo does the same once per file rather than once per match, which is what you want for file-level operations.