[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: some vi equivalents please?
From: |
Giorgos Keramidas |
Subject: |
Re: some vi equivalents please? |
Date: |
Fri, 31 Oct 2008 18:53:11 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) |
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.
- some vi equivalents please?, rustom, 2008/10/31
- RE: some vi equivalents please?, Drew Adams, 2008/10/31
- Re: some vi equivalents please?, Toby Cubitt, 2008/10/31
- RE: some vi equivalents please?, Parker, Matthew, 2008/10/31
- Re: some vi equivalents please?, Teemu Likonen, 2008/10/31
- Re: some vi equivalents please?,
Giorgos Keramidas <=