Vim 的全局命令,模式由逗号连接

Vim's global command with patterns joined by comma

根据文档,: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}吗?此语法记录在何处?

我刚刚在 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