replace word in vi

by

Please shareShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditDigg thisShare on StumbleUpon

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