Sunday, March 4, 2012

search n replace with multiple files in Vim

Suppose you have 100+ perl or C files and you want to replace 'xxx' with 'yyy' in all those files :
=================================
$vim *.pl
:bufdo! s/xxx/yyy/g
:wall
=================================


:wall -> save all.

same thing you can do with files opened in vim as in different windows.
:windo! s/xxx/yyy/g

other ways :
sed -i.bak -e 's/xxx/yyy/' *.pl ( with backup )
sed -i -e 's/xxx/yyy/' *.pl ( with no backup )
perl -p -i -e 's/xxx/yyy/g' *.pl ( careful no back up !! ).

Happy Vimming !!
@Satya

Followers