从文档中,:global
命令的语法为:
:[range]g[lobal]/{pattern}/[cmd]
Execute the Ex command [cmd] (default ":p") on the
lines within [range] where {pattern} matches.
我也遇到过:g
的用法:
:g/apples/+1,/peaches/ s/^/# /g
:g/start/+1,$ sort n
这里的/apples/+1,/peaches/
属于{pattern}
吗?该语法在哪里记录?
答案 0 :(得分:1)
我刚刚在Vim Tips Wiki中找到了:global
用法的解释:
:g/apples/,/peaches/ s/^/# /g
Insert "# " at the start of each line in all identified blocks.
:g/apples/ identifies each line containing "apples".
In each such line, .,/peaches/ s/^/# /g is executed
(the . is assumed; it means the current line, where "apples" occurs).
因此,/peaches/
在这里定义了替代命令的范围。有点令人困惑的部分(我在文档中没有提到)是初始'.'
在范围内是可选的。添加它会使命令更加明显:
:g/apples/.,/peaches/s/^/# /g