unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "David Combs" <dkcombs@panix.com>, <help-gnu-emacs@gnu.org>
Subject: RE: #1: How to do vi's 'g/foo/s/x/y/'  #2: + with a Q-R "yes/no?"
Date: Mon, 9 Apr 2007 00:48:19 -0700	[thread overview]
Message-ID: <BDEIJAFNGDOAGCJIPKPBMELGCDAA.drew.adams@oracle.com> (raw)
In-Reply-To: <ev8lno$p4e$1@panix2.panix.com>

> (1) How to do, in gnu-emacs,  vi's 'g/foo/s/x/y/':
>
> That is, "on all lines that contain regexp "foo", change x to y.
>
> And maybe also with option: only the first one on that line, or
> all of them?
>
> (2) Same as above, BUT WITH A QUERY-REPLACE-LIKE "YES|NO|!|etc" prompt.

You can do these things with Icicles.

`icicle-search' (`C-`') and other Icicles search commands (`icicle-occur',
`icicle-imenu', etc.) let you combine replacement with searching. Whenever
you are at a search hit, you can replace it (or all matches) by hitting a
key.

Searching (and replacement) is contextual:

1. You provide a context regexp (e.g. `.*foo.*' in your example - lines with
`foo').

2. Icicles presents all matches for that regexp (in the buffer, the region,
multiple buffers, or multiple saved regions) - as completion candidates.

3. You can navigate among the search hits, in order or with random (direct)
access, using `C-mouse-2', `C-RET', `C-next', or `C-prior'. The first two
are for direct access, the last two are for access in order.

4. You can replace any of the search hits with other text (e.g. `y' in your
example) selectively, using `S-C-mouse-2', `S-C-RET', `S-C-next', or
`S-C-prior'. The first time you use one of these, you are prompted for the
replacement string.

5. At any time, you can type input (e.g. `x' in your example), which can be
a regexp. Then, whatever that current input matches is replaced, instead of
the entire search hit (`foo') - but only in the context of the matching hits
(lines with `foo'). That is, `x' is replaced by `y', but only in lines that
contain `foo'. Each occurrence of `x' is treated individually.

6. You can choose instead to replace entire search hits (e.g. the whole line
with `foo'), instead of just the parts (`x') that match your current input.
You can toggle this at any time, using `C-,'. Even if you replace entire
search hits, you can still type input (e.g. `x') to filter the set of
initial matches (e.g. lines with `foo').

7. You can change the in-context matches by changing your minibuffer input
at any time: Erase `x' and type `j.*m', and matches of `j.*m' will be found
(and available for replacement) in lines that contain `foo'.

8. You can replace all matches of your current input (`x'), by using
`S-C-insert'.


Doc:
http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Search_Enhancements#SearchAn
dReplace

Code: http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Libraries

HTH

  parent reply	other threads:[~2007-04-09  7:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-07 17:51 #1: How to do vi's 'g/foo/s/x/y/' #2: + with a Q-R "yes/no?" David Combs
2007-04-08 10:28 ` Sam Peterson
2007-04-08 18:48   ` Markus Triska
2007-04-08 19:07 ` Peter Dyballa
2007-04-09  7:48 ` Drew Adams [this message]
     [not found] <mailman.1852.1176105200.7795.help-gnu-emacs@gnu.org>
2007-04-23  3:32 ` David Combs

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=BDEIJAFNGDOAGCJIPKPBMELGCDAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=dkcombs@panix.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).