From owner-freebsd-questions@FreeBSD.ORG Fri Aug 29 12:19:23 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 1F50D5D3; Fri, 29 Aug 2014 12:19:23 +0000 (UTC) Received: from fly.hiwaay.net (fly.hiwaay.net [216.180.54.1]) (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 DE77D13B2; Fri, 29 Aug 2014 12:19:22 +0000 (UTC) Received: from [192.168.0.27] (rbn1-216-180-19-61.adsl.hiwaay.net [216.180.19.61]) (authenticated bits=0) by fly.hiwaay.net (8.13.8/8.13.8/fly) with ESMTP id s7TCJL4e022868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 29 Aug 2014 07:19:21 -0500 Message-ID: <5400713F.7080500@hiwaay.net> Date: Fri, 29 Aug 2014 07:25:35 -0500 From: "William A. Mahaffey III" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 CC: FreeBSD Questions , owner-freebsd-questions@freebsd.org 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: Fri, 29 Aug 2014 12:19:23 -0000 On 08/29/14 06:51, Rodney Lewis wrote: > On 2014-08-29 09:20, Jamie Griffin wrote: > >> What is the best way to copy large sections of text in a file and >> copy it to another file, possibly a new file or not. Is vi even the >> best utility to do that? >> >> I have the source file open; I yank the text region then, do I open a >> new file/buffer first or is there a command to 'redirect' the data to? > > > 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 > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" > .... & of course, ex commands are available from within 'vi' using the same syntax as above .... -- William A. Mahaffey III ---------------------------------------------------------------------- "The M1 Garand is without doubt the finest implement of war ever devised by man." -- Gen. George S. Patton Jr.