Global search and replace with Vi/Vim
2007-05-01
Vi provides a few great shortcuts for handling search and replace of text within a file. On occasion, I've ran into situations where I've wanted to rename variables within a file while editting it in Vi.
First of all in order to indicate the entire file as the range of your change: utilize the '%' wildcard. In the example below, all references to 'foo' will be replaced with 'variable'. The 'g' represents that this change should be applied to all occurences (or globally):
:%s/foo/variable/g
If you just want to change references on lines 60 through 150 enter the following command:
:60,150 s/foo/variable/g
For more information on getting the most of Vi, please refer to the Best of VIM Tips.
posted by Brian Mansell @ 8:29:00 PM,
, links to this post
