From owner-freebsd-questions@FreeBSD.ORG Fri Aug 29 12:00:17 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 85868D49; Fri, 29 Aug 2014 12:00:17 +0000 (UTC) Received: from smtprelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by mx1.freebsd.org (Postfix) with ESMTP id 53CE41120; Fri, 29 Aug 2014 12:00:16 +0000 (UTC) Received: from smtprelay.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtpgrave02.hostedemail.com (Postfix) with ESMTP id 67FB544CF; Fri, 29 Aug 2014 11:51:13 +0000 (UTC) Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id C1502235AE; Fri, 29 Aug 2014 11:51:06 +0000 (UTC) X-Session-Marker: 726F646E65792E6C6577697340746F72746F697365626C6F672E636F6D X-Spam-Summary: 2, 0, 0, , d41d8cd98f00b204, rodney.lewis@tortoiseblog.com, ::owner-:::owner-, RULES_HIT:41:355:379:582:599:973:988:989:1152:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4418:4557:5007:6261:7903:7904:9108:10004:10226:10400:10848:11232:11658:11914:12517:12519:12740:13069:13161:13229:13311:13357:13870:21080, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:0:0 X-HE-Tag: night81_9a8bafd6a363 X-Filterd-Recvd-Size: 1830 Received: from webmail.hover.com (imap-ext [216.40.42.5]) (Authenticated sender: webmail@rodney.lewis@tortoiseblog.com) by omf04.hostedemail.com (Postfix) with ESMTPA; Fri, 29 Aug 2014 11:51:06 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 29 Aug 2014 12:51:06 +0100 From: Rodney Lewis To: Jamie Griffin Subject: Re: Moving Text In vi(1) To Another File In-Reply-To: <540037DE.4030404@gmail.com> References: <540037DE.4030404@gmail.com> Message-ID: <782f4b6466266500ebcc15173fef385b@tortoiseblog.com> X-Sender: rodney.lewis@tortoiseblog.com User-Agent: Roundcube Webmail/1.0.1 X-Originating-IP: [194.83.137.35] Cc: FreeBSD Questions , owner-freebsd-questions@freebsd.org 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:00:17 -0000 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