From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: some vi equivalents please? Date: Sat, 01 Nov 2008 07:32:58 -0600 Message-ID: References: <490B1DAD.8000205@dr-qubit.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1225546418 27812 80.91.229.12 (1 Nov 2008 13:33:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 1 Nov 2008 13:33:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 01 14:34:39 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 1KwGce-0003Cu-KD for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Nov 2008 14:34:36 +0100 Original-Received: from localhost ([127.0.0.1]:34029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KwGbX-00011p-Vw for geh-help-gnu-emacs@m.gmane.org; Sat, 01 Nov 2008 09:33:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KwGb9-00010q-5m for help-gnu-emacs@gnu.org; Sat, 01 Nov 2008 09:33:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KwGb7-0000zw-R2 for help-gnu-emacs@gnu.org; Sat, 01 Nov 2008 09:33:02 -0400 Original-Received: from [199.232.76.173] (port=57757 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KwGb7-0000zp-J3 for help-gnu-emacs@gnu.org; Sat, 01 Nov 2008 09:33:01 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:56046 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KwGb7-0005cN-CK for help-gnu-emacs@gnu.org; Sat, 01 Nov 2008 09:33:01 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KwGb3-0007lg-If for help-gnu-emacs@gnu.org; Sat, 01 Nov 2008 13:32:57 +0000 Original-Received: from c-67-161-145-183.hsd1.co.comcast.net ([67.161.145.183]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 01 Nov 2008 13:32:57 +0000 Original-Received: from kevin.d.rodgers by c-67-161-145-183.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 01 Nov 2008 13:32:57 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 55 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-67-161-145-183.hsd1.co.comcast.net User-Agent: Thunderbird 2.0.0.17 (Macintosh/20080914) In-Reply-To: <490B1DAD.8000205@dr-qubit.org> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:59327 Archived-At: Toby Cubitt wrote: > rustom wrote: >> 1. In vi I can delete a line that contains a with >> :g//d >> >> How is this done in emacs? > > M-x query-replace-regexp > > then enter "^.*.*$" as the regexp (no quotes), and leave the > replacement blank. > > >> 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? > > M-x query-replace-regexp > > then "^[^:]*\(.*\):\(.*\):.*$" for the regexp, and "\1 \2" for the > replacement (again, no quotes). > > The "^" and "$" both here and above are only there to prevent the regexp > matching across lines (unlike sed, regexp searches in an Emacs buffer > aren't line-oriented). Depending on your file, you might get away with > something simpler. E.g. for 2, if you know there will always be two > colons on every line, you could use "\(.*?\):\(.*?\):.*" instead ("?" > makes a wildcard non-greedy). > > query-replace-regexp is interactive, like query-replace. I find this > useful just to check I've got the regexps right, and then hit "!" once > I'm happy with it to replace all the rest non-interactively. The > non-interactive version is replace-regexp. Good advice! > There are no doubt many other ways to accomplish this in Emacs... Since rustom is used to vi's noninteractive way of using sed-like commands: C-M-h ; mark-whole-buffer C-u M-| ; shell-command-on-region sed '//d' C-M-h ; mark-whole-buffer C-u M-| ; shell-command-on-region sed 's/^\([^:]*\):\([^:]*\):.*$/\1 \2/' ; note the trailing / -- Kevin Rodgers Denver, Colorado, USA