Search This Blog

Saturday, October 24, 2009

Vi: Search and Replace Command

Vi, my favourite text editor in Unices. One problem I always encountered is search and replace command. The good news is you can find the answer by searching it on the internet. Anyway, I would like to keep record of what I've done.

Search and Replace all occurences in file:
:%s/OLD/NEW/g
Between 2 lines:
:#,#s/OLD/NEW/g
First occurence on current line:
:s/OLD/NEW
All occurences on current line:
:s/OLD/NEW/g