Syntax: [ADDR] S/source string/destination string/[Option] Global replacement command: % S/source string/destination string/g
[ADDR] indicates the search range. If it is omitted, it indicates the current row. For example, "1st" indicates the number of rows from to 20; "%": Indicates the entire file, which is the same as "1, $ "; "., $": From the current row to the end of the file;
S: indicates the replacement operation.
[Option]: indicates the operation type. For example, G indicates global replacement; C Indicates confirmation P indicates that the replacement result is displayed row by row (CTRL + l restore the screen ); If option is omitted, only the first matching string in each line is replaced; If special characters appear in the source string and target string, escape them "\"
The following are some examples: # Replace that or this with this or that.
: % S/\ (that \) or \ (this \) /\ U \ 2 or \ L \ 1/
--
# Replace child at the end of a sentence with children
: % S/child \([,.;! :?] \)/Children \ 1/g
--
# Change MGI/R/abox to MGI/R/asquare
: g/Mg \ ([Ira] \) box/S // mg // my \ 1 square/g <=>: g/mg [Ira] box/S/box/square/g
--
# Replace multiple spaces with one space
: % S/* // G
--
# use a space to replace one or more spaces after a period or a colon
: % S/\ ([:.] \) */\ 1/g
--
# delete all empty rows
: g/^ $/d
--
# delete all blank and empty rows
: g/^ [] [] * $/d
--
# insert two blank spaces at the beginning of each line
: % S/^/>/
--
# Add at the end of the next six rows.
:., 5/$ /. /
--
# reverse the object's row order
: G /. */m0o <=>: G/^/ M0o
--
# search for the starting line that is not a number and move it to the end of the file
: G! /^ [0-9]/M $ <=> G/^ [^ 0-9]/M $
--
# 12th to 17 lines of the file copy 10 words in the content to the end of the current file
: g/^/T $
~~~~ Function of repeated Times
--
# Write the content of the second row in the beginning row of chapter in the begin file
: G/^ chapter /. + 2 W> begin
--
:/^ Part2/,/^ Part3/G/^ chapter /. + 2 W> begin
--
:/^ Part2/,/^ Part3/G/^ chapter /. + 2 W> begin | + T $