g option (e.g.
s/pattern/replacement/g) for many tools that use regex-style pattern matching and the
:g command in
vim have pretty similar usage and meaning: match the given regex "globally", i.e., don't stop after the first match.
I have a two-fold question about this:
- Which came first, the
:gcommand or the
gpattern-matching flag, and in which tool? It looks like most tools (such as
sed) that use the
gflag in their pattern-matching are really just directly or indirectly emulating
ed. For instance, in the post-Perl age, most tools that use regex allow the
gflag because Perl does, and Perl, it would appear, does it because
Perl. So I wouldn't be surprised if the answer is "they were introduced simultaneously in the original
edtool, and have no historical precedent beyond that."
- Why is this called the
globaloption (or command)? There's really nothing "global" about it; the
:gcommand takes a range of lines just like any other
edcommand, and the
gflag doesn't extend the range of the search in any way (it just allows multiple hits). I suppose I can't think of a better name, but the chosen one just seems odd to me, so I'm wondering if there's some reason for it I'm not seeing.