<body><iframe src="http://www.blogger.com/navbar.g?targetBlogID=8010254895780061626&amp;blogName=lifeofbrian.org&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;homepageUrl=http%3A%2F%2Fwww.lifeofbrian.org%2Fblog%2F&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe"></iframe> <div id="space-for-ie"></div>

lifeofbrian
.
org

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.

Labels: ,

posted by Brian Mansell @ 8:29:00 PM, , links to this post