From: Giorgos Keramidas <keramida@ceid.upatras.gr>
To: help-gnu-emacs@gnu.org
Subject: Re: some vi equivalents please?
Date: Fri, 31 Oct 2008 18:53:11 +0200 [thread overview]
Message-ID: <87mygk670o.fsf@kobe.laptop> (raw)
In-Reply-To: a27b3eaa-e29d-44e7-b1f4-86e32f5bbbc4@s1g2000prg.googlegroups.com
On Fri, 31 Oct 2008 08:08:42 -0700 (PDT), rustom <rustompmody@gmail.com> wrote:
> 1. In vi I can delete a line that contains a <pat> with
> :g/<pat>/d
>
> How is this done in emacs?
I commonly use a keyboard macro for this sort of thing.
Type `C-x (' to start defining a macro, the run ``one iteration'' of a
complex set of commands, like `C-s pat C-a C-k C-k', and finally finish
the macro by typing `C-x )'. If the macro seems to work fine, it is
then easy to repeat it a specific number of times (C-u 100 C-x e) or
keep repeating the same macro by `C-x e e e e e e e ...'.
Macros are really powerful in Emacs. I have used them to convert text
files from one `ChangeLog' format to another, or to reformat a bit parts
of a text file that contain dates, and so on. The manual describes a
lot of even more interesting things you can do with keyboard macros.
Have a look at it by typing `C-h r m "Keyboard Macros" RET'.
> 2. match-variables:
> If I want to remove everything after the second : (in a file that has
> 3 fields separated with two :'s)
> I do
> :s/\(.*\):\(.*\):.*/\1 \2
> How do I do that in emacs?
Select a region (or the entire buffer with `C-x -h') and then type:
M-x replace-regexp RET \(.*\):\(.*\):.* RET \1 \2 RET
You can even get an interactive replace mode by typing:
M-x query-replace-regexp RET \(.*\):\(.*\):.* RET \1 \2 RET
Emacs is a bit more verbose when replacing regular expressions, but the
extra verbosity is a bit nice to see in the default case. Binding one
of these to a `shortcut' like `C-c R' is very easy
(global-set-key (kbd "C-c R") 'query-replace-regexp)
(global-set-key (kbd "<f4>") 'query-replace-regexp)
and you *still* get to see the verbose, helpful name of the command,
with the full feature set of command-completion when you need it.
next prev parent reply other threads:[~2008-10-31 16:53 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-31 15:08 some vi equivalents please? rustom
2008-10-31 15:01 ` Toby Cubitt
2008-11-01 13:32 ` Kevin Rodgers
2008-11-01 18:47 ` Reiner Steib
2008-10-31 15:53 ` Teemu Likonen
2008-10-31 15:59 ` Drew Adams
2008-10-31 16:01 ` Parker, Matthew
2008-10-31 16:53 ` Giorgos Keramidas [this message]
2008-10-31 17:22 ` Joost Kremers
2008-10-31 17:34 ` Giorgos Keramidas
2008-10-31 22:49 ` Xah
[not found] ` <mailman.2577.1225468814.25473.help-gnu-emacs@gnu.org>
2008-11-01 14:45 ` rustom
2008-11-01 14:52 ` rustom
2008-11-01 16:40 ` Giorgos Keramidas
2008-11-01 17:07 ` Drew Adams
[not found] ` <mailman.2646.1225559243.25473.help-gnu-emacs@gnu.org>
2008-11-02 15:30 ` rustom
2008-11-02 16:12 ` Drew Adams
[not found] ` <mailman.2710.1225642363.25473.help-gnu-emacs@gnu.org>
2008-11-03 7:19 ` rustom
2008-11-03 9:10 ` Drew Adams
2008-11-03 16:24 ` Giorgos Keramidas
2008-11-05 13:41 ` Ken Goldman
2008-11-06 7:08 ` rustom
2008-11-06 16:50 ` Drew Adams
2008-11-07 17:12 ` Johan Bockgård
2008-11-07 17:38 ` Drew Adams
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=87mygk670o.fsf@kobe.laptop \
--to=keramida@ceid.upatras.gr \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.