[Practical.Vim(2012.9)].Drew.Neil.Tip97 学习摘要

Meet The Global Command

The :global command allows us to run an Ex command on each line that matches a particular pattern. Let’s start by studying its syntax. The :global command takes the following form (see :h :g ):
:global命令可以让我们在每一行匹配特定pattern的文本上执行Ex命令。我们首先学习它的语法。:global命令形式如下

:[range] global[!] /{pattern}/ [cmd]

The default range for the :global command is the entire file (%). That sets it apart from most other Ex commands, including :delete, :substitute, and :normal, whose range is the current line (.) by default.
:global命令的默认range为(%) 也就是全文范围,和其他的Ex命令如:delete,:substitude,:normal的默认range不一样,这些命令的默认range为(.)当前行。
The {pattern} field integrates with search history. That means we can leave it blank and Vim will automatically use the current search pattern.
{pattern}可以和搜索历史整合。意味着我们可以把这一项留空,然后Vim会自动用当前的搜索pattern.
The [cmd] could be any Ex command except for another :global command
[cmd]可以是除了:global命令的任何的Ex命令。

We can invert the behavior of the :global command either by running :global! or :vglobal (mnemonic: invert). Each of these tells Vim to execute [cmd] on each line that doesn’t match the specified pattern.
我们可以反转:global的效果通过使用:global!:vglobal.这些符号告诉Vim在每一条不匹配pattern的行上执行命令[cmd]

The :global command works by making two passes through the lines specified by [range]. In the first pass, Vim marks each line that matches the specified {pattern}. Then on the second pass, the [cmd] is executed for each marked line. The [cmd] can accept a range of its own, which allows us to operate on multiline regions.
:global命令执行时,由[range]指定的行将会被传递两次。在第一次传递时,Vim标注那些匹配{pattern}的行,然后在第二次传递时,这些被标记的行执行[cmd]命令。[cmd]命令可以接受range本身,允许我们在多个行上执行命令。

你可能感兴趣的:(Linux,&,Unix,Vim)