From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giorgos Keramidas Newsgroups: gmane.emacs.help Subject: Re: some vi equivalents please? Date: Fri, 31 Oct 2008 18:53:11 +0200 Organization: SunSITE.dk - Supporting Open source Message-ID: <87mygk670o.fsf@kobe.laptop> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1225474892 16770 80.91.229.12 (31 Oct 2008 17:41:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Oct 2008 17:41:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 31 18:42:33 2008 connect(): Connection refused 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 1Kvy0s-0004Un-Pp for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Oct 2008 18:42:23 +0100 Original-Received: from localhost ([127.0.0.1]:46731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kvxzm-0006P2-4F for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Oct 2008 13:41:14 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!goblin2!goblin.stu.neva.ru!news.net.uni-c.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) Cancel-Lock: sha1:dqUrtEAOe0F3MiYiKJuvbRTpRp4= Original-Lines: 45 Original-NNTP-Posting-Host: 77.49.247.157 Original-X-Trace: news.sunsite.dk DXC=Q[fJelHckFmoTl; T5CL^MjgbH?lJH1Tkjl0><]e:MKZVh]_8OI[_Eoeg Original-X-Complaints-To: staff@sunsite.dk Original-Xref: news.stanford.edu gnu.emacs.help:163960 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:59303 Archived-At: On Fri, 31 Oct 2008 08:08:42 -0700 (PDT), rustom wrote: > 1. In vi I can delete a line that contains a with > :g//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 "") '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.