Tip 97: Meet the Global Command
Return to the top: <<Practical Vim>>
Format of :global
:
:[range] global[!] /{pattern}/ [cmd]
References:
# If you open the file in vim, # then you can \"ayy@a the next line to execute the vim command: :h :g
-
The default range for the
:global
command is the entire file (%
).-
Most other Ex commands (
:delete
/:substitute
/:normal
): the current line (.
) by default.
-
Most other Ex commands (
-
The
{pattern}
field integrates with search history → we can leave it blank and Vim will automatically use the current search pattern. -
The
[cmd]
could be any Ex command except for another:global
command.-
If we don't specify a
[cmd]
, then Vim will use:print
by default.
-
If we don't specify a
-
:global!
/:vglobal
: invert the behavior of the:global
command.