Vim string replacement and vim string replacement
In the project test of the company, you need to modify the multi-path in the vi editing. At this time, you have used the string replacement knowledge. Here I have sorted it out myself.
I. Basic Content replacement without special symbols
- : S/old/new/Replace the first old value of the current row with new. If the new value is left blank, editing is not affected.
- : S/old/new/g replace all old values of the current row with new
- : N, $ s/old/new/Replace the first old value from row n to row n as new
- : N, $ s/vivian/sky/g to replace all the old values from row n to the last row. Here, there is no space between $ and s, personal habits: space (n is a number, if n is ., starting from the current row to the last row)
- : % S/old/new/(equivalent to: g/old/s // new/) Replace the first old of each row with new
- : % S/old/new/g (equivalent to: g/old/s // new/g)
Ii. Replacement of special characters
- : S # old/# new/# Replace the first old/of the current row with new/
- : 1, $ s #/old/#/new/# replace all the existing strings in the body with the string new/
Iii. self-testing
- : 1, $ s/new/old =: 1, $ s/new/old/g =: % s/old/new/g. The effect of changing the strings is the same.