CentOS Linux Server Guide

Vi Editor - Replace words, sentences , string using keyboard

Before performing any search operation, you must first make sure that you are in command mode.
Keyboard  Operation
:s/string1/string2/g  replace all string1 to string2 within the current line
:%s/string1/string2/g  replace all string1 to string2 within the entire file

 

Example

In the following example, we search and replace all word matched 'error' with new string 'normal'
:%s/error/normal/g

 

In the following example, we search and replace all 'error' with new string 'normal' with 30th to 40th lines
:30,40/error/normal/g

 

Read more on Visual Editor (VI)



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy