Sunday, September 27, 2009

search/replace on VIM

here is the syntax of how to search/replace string or characters in vim...

:(range) s/(old to be search string)/(new string)

example:
this command will replace all "www" to "emspree" in lines 1 to 10

:1,10 s/www/emspree

if you want only a line,

:s/www/emspree

however if you want to replace a string with a "/"
it will replace www/site to maryon/newsite

:1,10 s/www\/site/maryon\/newsite

on whole file search/replace

:%s/www/emspree

if you want to have a confirmations

:%s/www/emspree/c

No comments:

Post a Comment