Article View: gnu.emacs.help
Article #189111Re: Operating on lines containing a pattern
From: Dave Sill
Date: Fri, 03 May 1991 17:33
Date: Fri, 03 May 1991 17:33
34 lines
1820 bytes
1820 bytes
In article <BAUMGART.91May3100021@esquire.esquire.dpw.com>, baumgart@esquire.dpw.com (Steve Baumgarten) writes: >In "vi" (boo! hiss!), you can do something like this: > > :g/pattern/d > >to delete all the lines in a file that contain the pattern "pattern". There's delete-matching-lines for that. >Or this: > > :g/pattern/s/p1/p2/ > >to substitute p2 for p1 in all lines containing the pattern "pattern". > >Is there some way to do this in Emacs, short of writing elisp code? C-x ( C-s pattern ESC C-e C-@ C-a M-x narrow-to-region RET M-x replace-string p1 RET p2 RET M-x widen C-x ) to define a macro to do the replacement once. Followed by C-u 0 C-x e to repeat the macro for the rest of the file. I know it's not pretty, but it's completely general: you can do whatever you want to the matching lines, not just substitutions. >Any suggestions? Then again, there's always vi-mode, or vip-mode, or... -- Dave Sill (de5@ornl.gov) It will be a great day when our schools have Martin Marietta Energy Systems all the money they need and the Air Force Workstation Support has to hold a bake sale to buy a new bomber.
Technical Details
Message-ID:
<1991May3.173325.29233@cs.utk.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!elroy.jpl.nasa.gov!ncar!gatech!utkcs2!ornl.gov!de5References:
<BAUMGART.91May3100021@esquire.esquire.dpw.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,80ffebd709a40a03 X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-05-04 00:05:02 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!elroy.jpl.nasa.gov!ncar!gatech!utkcs2!ornl.gov!de5 From: de5@ornl.gov (Dave Sill) Newsgroups: gnu.emacs.help Subject: Re: Operating on lines containing a pattern Message-ID: <1991May3.173325.29233@cs.utk.edu> Date: 3 May 91 17:33:25 GMT References: <BAUMGART.91May3100021@esquire.esquire.dpw.com> Sender: usenet@cs.utk.edu (USENET News Poster) Reply-To: Dave Sill <de5@ornl.gov> Organization: Oak Ridge National Laboratory Lines: 34