Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Find and Replace Across Files

Vim can find and replace strings across files, just like other text editors. It’s really (sort of) easy.

First, load all the files you want to change into the Vim buffer with a splatted directory.

:args path/to/files/*/*

Then, execute the substitution.

:argdo %s/old_string/new_string/ge | update

The e flag is important; it tells Vim not to issue an error if the search pattern fails. This will prevent No Match errors from breaking the chain.

Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the Vim Chicago Meetup hosted at our Chicago office.