Vim Global Replacement file:
The syntax is: [addr]s/source string/destination string/[option]the Global Substitution command is::%s/source string/destination string/g
[addr] Indicates the scope of the search, which represents the current row when omitted. such as: "1,20": the line from line 1th to 20, "%": represents the entire file, with "1,$"; "., $": from the current line to the end of the file;
s: Represents the Replace Operation
[ Option]: Indicates the type of operation , such as: g means global substitution; c means to confirm p indicates that the substitution results are displayed line by row (Ctrl + L recovery screen); when option is omitted, only the first matching string of each row is replaced; if special characters appear in the source string and the destination string, you need to escape with "\"
Here are some examples: #将That or this is replaced with this or so
:%s/\ (that\) or \ (this\)/\u\2 or \l\1/
-- < br> #将句尾的child换成children
:%s/child\ ([,.;!:?] \)/children\1/g
--
#将mgi/r/abox change to Mgi/r/asquare
: g/mg\ ([ira]\) box/s//mg//my\1square/g <=> : g/mg[ira]box/s/box/square/g
--
#将多个空格换成一个空格
:%s/ *//g
--
# Use a space to replace the period or one or more spaces following the colon
:%s/\ ([:.] \) */\1/g
--
#删除所有空行
: g/^$/d
--
#删除所有的空白行和空行
: g/^[ ][ ]*$/d
--
# Insert two blanks at the beginning of each line
:%s/^/> /
--
#在接下来的6行末尾加入.
:., 5/$/./
--
#颠倒文件的行序
:g/.*/m0o < + =: g/^/m0o
--
#寻找不是数字的开始行 and move it to the end of the file
: g!/^[0-9]/m$ <=> g/^[^0-9]/m$
--
# Copy the 12th to 17th line of the file 10 words to the end of the current file
: 1,10g/^/12,17t$
~ ~ ~ ~ ~ ~ ~ ~
#将chapter开始行下面的第二行的内容写道begin文件中
: g/ ^chapter/.+2w>>begin
--
:/^part2/,/^part3/g/^chapter/.+2w>>begin
--
:/^part2/,/^part3/ g/^chapter/.+2w>>begin|+t$
Vim (5): Global substitution