The difference seems primarily to be that :g/123/d | g/456/d
considers d | g/456/d
as the on-each-line command (:help :bar
). The :execute
prevents :global
from eating the bar, so you have two separate commands. (Details on the structure at the end.)
This matters: in :g/123/d | g/456/d
, if 123
is not found, _none of d | g/456/d
runs. But in :execute 'g/123/d' | execute 'g/456/d'
, if 123
, is not found, first d
is not run, then execute 'g/456/d'
is not run because the previous command errored.
Finally, by prefixing the first command with :silent!
(:silent
does not consume |
, so only the first command is silenced), you guarantee that execute 'g/456/d'
runs no matter what.
A small representation of the parsing differences:
:silent! g/123/d | g/456/d
: [silently] [for each line containing 123
, do] [delete, then if that succeeded, [for each line containing 456
, do [delete]]]
:silent! execute 'g/123/d' | execute 'g/456/d'
: [[silently] [for each line containing 123
, do] [delete]], then if that succeeded (which it will because of [silently]), [[for each line containing 456
, do] [delete]].
Extract from :help :bar
to justify parsing:
These commands see the '|' as their argument, and can therefore not be
followed by another Vim command:
[…]
:global