From owner-freebsd-questions@FreeBSD.ORG Sat Aug 30 10:08:18 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B24AA403 for ; Sat, 30 Aug 2014 10:08:18 +0000 (UTC) Received: from mail-wi0-x22a.google.com (mail-wi0-x22a.google.com [IPv6:2a00:1450:400c:c05::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 487F018CB for ; Sat, 30 Aug 2014 10:08:18 +0000 (UTC) Received: by mail-wi0-f170.google.com with SMTP id cc10so351415wib.3 for ; Sat, 30 Aug 2014 03:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=PJT91SW0kkoja44arFcS6YBfRe1oNKb+9Go6LoMRkdE=; b=CATus34+2zZVcGT51oa282BFBplr9uOqf5x6SZ7a+5hGXuuIIHWuzq3eiVDspGkV4m GfOQ1EhQVJ5LA1bXCoJ+OLBydBhxrRjVCBziyH89UyczsNgdWre0IWVSxn4cZ+2OTmxJ bVBzXI+Y/JlJoFGoY9ekYpXUuneIOSS8DVV5o2Fpt1tK+HsOpF/eDcDhXe1tvoprgb3C yb35P2Yiv+jf0Ukv1tt85tBLxUbaAoLY5aPjHQT/eE0nObxc9/jD7DESuinS8Ptp/oJ7 uJHO96iuT+Aji1C7k86PPraXvgEzfBVsm+NTuULE5JGTicEkSlA66DcycbdqkYTDXS0Q GdfQ== X-Received: by 10.180.90.6 with SMTP id bs6mr9549031wib.47.1409393296517; Sat, 30 Aug 2014 03:08:16 -0700 (PDT) Received: from kontrol.kode5.net (host81-157-206-146.range81-157.btcentralplus.com. [81.157.206.146]) by mx.google.com with ESMTPSA id ka3sm6299052wjc.3.2014.08.30.03.08.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Aug 2014 03:08:16 -0700 (PDT) Message-ID: <5401A28F.2060404@gmail.com> Date: Sat, 30 Aug 2014 11:08:15 +0100 From: Jamie Griffin User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Polytropon Subject: Re: Moving Text In vi(1) To Another File References: <540037DE.4030404@gmail.com> <782f4b6466266500ebcc15173fef385b@tortoiseblog.com> <5401780A.2040208@gmail.com> <20140830091803.35b9d646.freebsd@edvax.de> In-Reply-To: <20140830091803.35b9d646.freebsd@edvax.de> Content-Type: text/plain; charset=windows-1252; format=flowed 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 10:08:18 -0000 On 30/08/2014 08:18, Polytropon wrote: > 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). > > > Yeah I was quite interested in joe since I read your recommendation, so i've installed it already to try it out.