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
:globalcommand 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:globalcommand.-
If we don't specify a
[cmd], then Vim will use:printby default.
-
If we don't specify a
-
:global!/:vglobal: invert the behavior of the:globalcommand.