From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help 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 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1176105048 13614 80.91.229.12 (9 Apr 2007 07:50:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 9 Apr 2007 07:50:48 +0000 (UTC) To: "David Combs" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 09 09:50:05 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HaodY-0003GE-O3 for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Apr 2007 09:50:05 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HaohL-0005XS-CK for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Apr 2007 03:53:59 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Haogh-0004IU-Jc for help-gnu-emacs@gnu.org; Mon, 09 Apr 2007 03:53:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Haogf-0004DU-GB for help-gnu-emacs@gnu.org; Mon, 09 Apr 2007 03:53:18 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Haogf-0004Ck-8R for help-gnu-emacs@gnu.org; Mon, 09 Apr 2007 03:53:17 -0400 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Haocp-0002qh-Sq for help-gnu-emacs@gnu.org; Mon, 09 Apr 2007 03:49:20 -0400 Original-Received: from rgmgw3.us.oracle.com (rgmgw3.us.oracle.com [138.1.186.112]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l397nCbo003063; Mon, 9 Apr 2007 02:49:12 -0500 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by rgmgw3.us.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l397KrIa016612; Mon, 9 Apr 2007 01:49:12 -0600 Original-Received: from dhcp-amer-csvpn-gw2-141-144-72-45.vpn.oracle.com by acsmt351.oracle.com with ESMTP id 2599698441176104915; Mon, 09 Apr 2007 00:48:35 -0700 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-Whitelist: TRUE X-Whitelist: TRUE X-Brightmail-Tracker: AAAAAQAAAAI= X-detected-kernel: Linux 2.4-2.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42498 Archived-At: > (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