Search and replace all string instances in vim editor

vim

When I was working on a very, very long script, I wanted to find a way to quickly and easily replace all string instances.

vim includes a :substitute command that searches a pattern in a body of text, then replaces all the instances available.

:%s/foo/bar/g
Find each occurrence of 'foo', and replace it with 'bar'.
:5,12s/foo/bar/g 
Change each 'foo' to 'bar' for all lines from line 5 to line 12 inclusive.