From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Toby Cubitt Newsgroups: gmane.emacs.help Subject: Re: some vi equivalents please? Date: Fri, 31 Oct 2008 16:01:01 +0100 Message-ID: <490B1DAD.8000205@dr-qubit.org> References: Reply-To: Toby Cubitt NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1225468999 26820 80.91.229.12 (31 Oct 2008 16:03:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Oct 2008 16:03:19 +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 17:04:21 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 1KvwSS-00051g-Cg for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Oct 2008 17:02:45 +0100 Original-Received: from localhost ([127.0.0.1]:58499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KvwRK-0004zU-Kk for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Oct 2008 12:01:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KvwR1-0004zF-Ng for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 12:01:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KvwR0-0004z3-KE for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 12:01:15 -0400 Original-Received: from [199.232.76.173] (port=34876 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KvwR0-0004z0-Hq for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 12:01:14 -0400 Original-Received: from mail.geekisp.com ([216.168.135.169]:45197 helo=starfish.geekisp.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KvwR0-0007Xr-0U for help-gnu-emacs@gnu.org; Fri, 31 Oct 2008 12:01:14 -0400 Original-Received: (qmail 16456 invoked by uid 1003); 31 Oct 2008 16:01:06 -0000 Original-Received: from [192.168.2.9] (localhost.geekisp.com [127.0.0.1]) by localhost.geekisp.com (tmda-ofmipd) with ESMTP; Fri, 31 Oct 2008 12:01:02 -0400 User-Agent: Thunderbird 2.0.0.17 (X11/20080929) In-Reply-To: X-Delivery-Agent: TMDA/1.1.11 (Ladyburn) X-Primary-Address: toby@dr-qubit.org X-detected-operating-system: by monty-python.gnu.org: OpenBSD 3.0-3.9 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:59298 Archived-At: 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. There are no doubt many other ways to accomplish this in Emacs... HTH, Toby