Pages

Tuesday, January 17, 2012

String replacing in VIM.


To replace a string with vim do the following:
:%s/string/replace string/g
% - means search and replace in whole file
If you want to replace stuff in certain portion of the file you can do following:

:20,50 s/string/replace string/g
:20,50 will search and replace string in rows between 20 and 50

Escaping special chars with \. Look at following example. I need to replace /usr/src/ with /var/log/archive in one of my scripts:
:%s/\/usr\/src/\/var\/log\/archive/g

No comments: