Multiple file search and replace using VIM and renaming files with the command line.

This sets VIM to auto write changes. You can also use :set hidden. Either one will stop VIM from complaining about not saving the files.

:set aw

Search and replace is two steps.

Find the files that have things to be replaced with :grep.

Use :cdo to run the VIM substitute command on all the files in the quickfix list.

:grep Something --iglob '!db/**'
:cdo s/Something/Newthing/gc

If you’re not using ripgrep then remove the --iglob and ignore the db directory.

Rename files

I really like the fd command line replacement for find. It’s fast, is more intuitive, and respects .gitignore when searching.

I also used the rename application. Install on OS X with brew.

brew install rename

fd session -E 'db/**' . | rename -n -s session conversation

fd session -E 'db/**' . | rename -s session conversation

Sometime you might need to run the rename command multiple times if the word being replaced is in the path multiple times.

You can use the -n flag to just show the changes.