From owner-freebsd-questions@FreeBSD.ORG Sat Aug 30 07:18:13 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D510264B for ; Sat, 30 Aug 2014 07:18:13 +0000 (UTC) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 971A617B2 for ; Sat, 30 Aug 2014 07:18:13 +0000 (UTC) Received: from r56.edvax.de (port-92-195-111-1.dynamic.qsc.de [92.195.111.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id CD5AE276AE; Sat, 30 Aug 2014 09:18:03 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id s7U7I3s4002443; Sat, 30 Aug 2014 09:18:03 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sat, 30 Aug 2014 09:18:03 +0200 From: Polytropon To: Jamie Griffin Subject: Re: Moving Text In vi(1) To Another File Message-Id: <20140830091803.35b9d646.freebsd@edvax.de> In-Reply-To: <5401780A.2040208@gmail.com> References: <540037DE.4030404@gmail.com> <782f4b6466266500ebcc15173fef385b@tortoiseblog.com> <5401780A.2040208@gmail.com> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Aug 2014 07:18:13 -0000 On Sat, 30 Aug 2014 08:06:50 +0100, Jamie Griffin wrote: > > On 29/08/2014 12:51, Rodney Lewis wrote: > > > > There are several ways to do this but I prefer the old ex commands. > > It's just the way my brain works. > > > > First I enable visible line numbers so I know what's where. > > > > :set nu > > > > You can then use the following to write out to a new file. > > Select lines 10 to 30 > > :10,30w ~/newfile > > > > Or append lines 45 to 66 to newfile > > > > :45,66w >>~/newfile > > > > > > To copy text chunks around a file > > Copy line 45,66 and insert at line 90 > > > > :45,66co90 > > > > Or substitute mo to move it > > > > :45,66mo90 > > > > You can also use d to delete chunks of text > > Delete line 78 to 88 > > :78,88d > > > > Hope this helps > > > > Rodney > > > > Hi to everyone who contributed, thanks for these tips - they are very > helpful. I'm reorganising a large configuration file and I want to > modularise it by separating elements into sub-sections so being able to > add sections of text to existing files is necessary. This is easy to remember and consistent with the logic and the workflow of vi / ex. I will add this to restoring my vi skills. :-) Note that the joe idea I mentioned was more of an interactive approach, while the vi solution is more explicit (enable line numbers, then use then - instead of navigating in the source text, marking the beginning and the end of the selection). Also the more direct way of "write to a file" will make the whole task easier (and therefore faster to perform). An andvantage of the joe idea might be that you can "spend more interactive time in the files", if that is needed (for example to add or modify text). -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...