: s/str1/str2/replaces the current line the first str1 is str2
: S/str1/str2/g replaces the current line with all str1 as str2 (note that the S/XX/XXX/G statement starts with S and the middle space is treated as part of the string)
: N,n2 s/str1/str2/replaces the nth row start to the first str1 of each row in line N2 str2
: N,n2 s/str1/str2/g replaces the nth line to the N2 row, and all str1 is str2 for each row
N is a number, and if N is., represents the current row. If N2 is $, the last line is indicated.
:% s/str1/str2/replaces the first str1 of each line as str2
:% s/str1/str2/g replaces all str1 in each row as str2
You can use # as a delimiter, at which time the middle/not as a delimiter
: s#str1/#str2/# Replace the current row the first str1/is str2/
Summarize the above substitution commands:
1. G At the end of the command:
Plus g, which indicates that each occurrence of the search string is replaced;
No g, which means that only the first occurrence of the search string is replaced;
2. Multi-line Replacement:
Sentence First Plus: n,n2
3. Full-text replacement:
First sentence plus:%
Sentence First Plus: 1,$
4. Use # as a delimiter to let/also be part of a string.
Use/As a delimiter, you can make # also as part of a string.
They just complement each other.
Vim: String substitution