Search and replace in linux vi editor

:%s/oldstring/newstring/gc 

This command will replace all the occurences for oldstring with newstring after confirming for each existence (c in the end tells vim to ask for confirmation).

More on search replace – http://vim.wikia.com/wiki/Search_and_replace

Some other useful commands are

/ for search 
n find next while search (after /)
N find previous while searcg (after /)

:$ last line of file
:0 first line of file

http://www.cs.colostate.edu/helpdocs/vi.html

Leave a Reply

Your email address will not be published. Required fields are marked *