Meet the Global Command
The :global
command allows us-to-run an Ex-command on the matches a particular pattern. Let's start by studying its syntax. The:global command takes the following form (See:h: g):
: The global command allows us to execute the ex command on each line of text that matches a particular pattern. We first learn the grammar of it. : The Global command form is as follows
global/{pattern}/ [cmd]
The
The default range for The:global command is the entire file (%). That's sets it apart from the very other EX commands, including:d elete,: Substitute, And:normal, whose range are the current Li NE (.) By default.
: The default range for the global command is (%) that is, the full-text range, and the other ex commands, such as the default range for Delete,:substitude,:normal: The default range for these commands is (.) The current row. The
the {pattern} field integrates with search history. That means we can leave it blank and Vim would automatically use the current search pattern.
{pattern} can be integrated with search history. means that we can leave this item blank, and Vim will automatically use the current search pattern.
The [cmd] could is any ex command except for another:global command
[cmd] can be anything other than: the global command.
We can invert the behavior of the:global command either by running:global! Or:vglobal (Mnemonic:invert). Each of the these tells Vim-to-execute [cmd] on the doesn ' t match the specified pattern.
We can reverse: the effect of global is by using :global!
or :vglobal
. These symbols tell vim to execute commands on each line that does not match the pattern[cmd]
The:global command works by making-passes through the lines specified by [range]. In the first pass, Vim marks the matches the specified {pattern}. Then on the second pass, the [CMD] are executed for each marked line. The [CMD] can accept a range of its own, which allows us to operate on multiline regions.
: When the global command executes, the row specified by [range] is passed two times. At the first pass, VIM labels the rows that match {pattern} , and then, on the second pass, the marked rows execute the [cmd] command. The [cmd] command can accept the range itself, allowing us to execute commands on multiple lines.
[Practical.vim (2012.9)]. DREW.NEIL.TIP97 Study Summary