From owner-freebsd-questions@FreeBSD.ORG Sat Aug 30 07:06:53 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 DA8F4309 for ; Sat, 30 Aug 2014 07:06:53 +0000 (UTC) Received: from mail-we0-x230.google.com (mail-we0-x230.google.com [IPv6:2a00:1450:400c:c03::230]) (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 6FC2315BA for ; Sat, 30 Aug 2014 07:06:53 +0000 (UTC) Received: by mail-we0-f176.google.com with SMTP id q59so3100406wes.35 for ; Sat, 30 Aug 2014 00:06:51 -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:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=Ls8z6GQUfXLc8gzNpY3EZ7N4iAPcOwF2y0yn+BcWuXs=; b=NcynYgZODrEZyKA/YyRtWEQbpwfr/+Q2ly2FuJZDh3EEtJbYkkNoETJwskANWZmG2I uXPbGJaKVMgH0tGkiqSY+s/aTZIiQ1H9fLdXllxN61jnhB03nQE6yDoJKSXjNLudJZqf o8h3pVm1rAXAk/V9p40npyrJWi+9y0wXfmKlHahzk71c5GZbmJ167IL5pntdQ2Q9Dzgt WV3sr1yozJoziE+SDLDhCEpqwTlYCTPJiTXcX6KnKIjSD+d67QQw4aDMc5yoL2UNlv2E VctBqgcxBaYyYLyMpz3BR4lm2NyySM+ayfjRvDRvTUq/w1Z4W+XuHiRGRr1tQx0LQKYF 30rg== X-Received: by 10.194.59.42 with SMTP id w10mr18561546wjq.15.1409382411811; Sat, 30 Aug 2014 00:06:51 -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 hf9sm3087420wib.11.2014.08.30.00.06.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Aug 2014 00:06:51 -0700 (PDT) Message-ID: <5401780A.2040208@gmail.com> Date: Sat, 30 Aug 2014 08:06:50 +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: FreeBSD Questions Subject: Re: Moving Text In vi(1) To Another File References: <540037DE.4030404@gmail.com> <782f4b6466266500ebcc15173fef385b@tortoiseblog.com> In-Reply-To: <782f4b6466266500ebcc15173fef385b@tortoiseblog.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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:06:53 -0000 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. Thanks again