9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Silas McCroskey <inkswinc@gmail.com>
To: 9fans <9fans@9fans.net>
Subject: Re: [9fans] ed regular expressions in sam
Date: Tue, 20 Jul 2021 11:32:31 -0700	[thread overview]
Message-ID: <CAHjwAuxJv1KEbGmP9EdLXtz09YjUcArpzExcWhU_EDk5aQZ6=w@mail.gmail.com> (raw)
In-Reply-To: <16267959280.0118f7b.178764@composer.9fans.topicbox.com>

> 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	other threads:[~2021-07-20 18:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20 10:17 revcomninos
2021-07-20 10:32 ` Alex Musolino
2021-07-20 11:00   ` revcomninos
2021-07-20 11:12     ` umbraticus
2021-07-20 13:06       ` Rob Pike
2021-07-20 13:45       ` revcomninos
2021-07-20 14:21         ` revcomninos
2021-07-20 14:31           ` Silas
2021-07-20 15:45             ` revcomninos
2021-07-20 18:32               ` Silas McCroskey [this message]
2021-07-20 18:57                 ` revcomninos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHjwAuxJv1KEbGmP9EdLXtz09YjUcArpzExcWhU_EDk5aQZ6=w@mail.gmail.com' \
    --to=inkswinc@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).