Sunday, 17 April 2016

How to search and replace in vi editor



Change to normal mode with ESC

Search

Search STRING forward   /STRING
Search STRING backward  ?STRING
Search next   n
Search previous  N


Replace

Same as with sed, Replace OLD with NEW
First occurrence on current line      :s/OLD/NEW
Globally (all) on current line:        :s/OLD/NEW/g
Between two lines #,#:                 :#,#s/OLD/NEW/g
Every occurrence in file:              :%s/OLD/NEW/g

No comments:

Post a Comment

Note: only a member of this blog may post a comment.