Reprinted: http://andyss.blog.51cto.com/315552/131652
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 ); if option is omitted, only the first matching string in each line is replaced. If special characters appear in the source string and destination string, escape "\".
Here 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 spaces to replace one or more spaces after the ending periods or colons
: % S/\ ([:.] \) */\ 1/g
--
# Deleting 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/$ /./
--
# Reversing the object's line 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 $
--
# Copy 10 words from lines 12th to 17 of the file to the end of the current file
: G/^/T $
~~~~ Function of repeated times
--
# Write the content of the second row below the beginning of chapter to the begin File
: G/^ chapter/. + 2 W> begin
--
:/^ Part2/,/^ Part3/G/^ chapter/. + 2 W> begin
--
:/^ Part2/,/^ Part3/G/^ chapter/. + 2 W> begin | + T $