> I have yet gotten to this usage of "g" after "s".

The key difference here is not in the behavior of suffixed 'g', but in
how selections are made and operated on in the first place.

Ed's "selection" (aka dot, as you can reference it with '.') is always
a full, single line. It can *iterate* over multiple lines with
prefixed 'g', but each command (e.g. 's') will be run against only one
line at a time. As a result, suffixed 'g' always means "allow multiple
edits within this line" (alternatively, *not* suffixing with 'g' means
"only edit the first occurence of each line").

Sam's "selection" is more arbitrary -- it can be (and frequently is)
less than a line or multiple lines at once. In this case 'g' takes on
a different meaning -- "allow multiple edits within this selection" --
meaning if you *don't* pass 'g', and you're working with a multi-line
selection, only the first match in the entire selection will be
changed by the 's', regardless of whether other matches occurred on
separate lines.

As rob pointed out, interposing an 'x' without a regex will split the
selection into lines and iterate over each, getting you back to the
line-at-a-time behavior that is often easier to reason about.

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Te7fcdc06a68bb777-M4fb1e908c2fdeb00adbda077
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to