replace word in vi

by
Share this Article: Facebook0Google+0Twitter0LinkedIn0Reddit0Pinterest0StumbleUpon0Digg

To replace word in vi, the below steps can be used(replace OLD with NEW). Please make sure you are in command(normal) mode:

  1. to replace first occurrence of OLD to NEW on current line
    • :s/OLD/NEW
  2. to replace all occurrence of OLD to NEW on current line
    • :s/OLD/NEW/g
  3. to replace all occurrence of OLD to NEW between two line numbers (# are the line numbers)
    • :#,#s/OLD/NEW/g
  4. to replace every occurrence of OLD to NEW on current file
    • :%s/OLD/NEW/g

Source:Linuxwave

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook0Google+0Twitter0LinkedIn0Reddit0Pinterest0StumbleUpon0Digg