vi / vim can be used :s
to replace the string command. In the past, only one format was used to replace the full text. Today, I found that there are many ways to write this command (vi is really powerful, and there is still a lot to learn). Record a few here for easy query in the future.
replace
:s/vivian/sky/
Replace the first vivian of the current line with sky:s/vivian/sky/g
Replace all vivian in the current line with sky:n,$s/vivian/sky/
Replace the first vivian of each line from the beginning of the nth line to the last line with sky:n,$s/vivian/sky/g
Replace all vivian from the beginning of the nth line to the last line with sky
(n is a number, if n is . , it means from the current line to the last line):%s/vivian/sky/
(Equivalent to:g/vivian/s//sky/
) Replace the first vivian of each line with sky:%s/vivian/sky/g
(Equivalent to: g/vivian/s//sky/g) To replace all vivian in each line with sky,
you can use # as a separator, and the / appearing in the middle will not be used as a separator:s#vivian/#sky/#
Replace the first vivian/ of the current line with sky/:%s+/oradata/apras/+/user01/apras1+
(Use + to replace / ): /oradata/apras/ is replaced with /user01/apras1/