[plug] re: replacing text in search

Craig Ringer craig at postnewspapers.com.au
Sat Aug 2 14:41:46 WST 2003


> In vim how do I do a search and replace for the following
> /sbin/iptables?  I've tried %s//sbin/iptables/g but this does not work. 
> I'm need to include the / character in the search.

:1,$s/\/sbin\/iptables/REPLACEMENTTEXT/g

At least, if you want to do an automatic find-and replace across the 
entire document, replacing all instances not just the first one on a 
line, this is what you'll want. Note the use of escapes on the slashes, 
and the trailing /g to ensure it replaces every instance.

I'm not sure if there's a way to avoid having to use the :1,$ notation 
to say 'all of file' but when I've tried to use s regex without this, ie
:s/blah/bloh/g
it fails.

Craig Ringer



More information about the plug mailing list