Date: Sat, 30 Aug 2014 11:08:15 +0100 From: Jamie Griffin <griffin8j@gmail.com> To: Polytropon <freebsd@edvax.de> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Moving Text In vi(1) To Another File Message-ID: <5401A28F.2060404@gmail.com> In-Reply-To: <20140830091803.35b9d646.freebsd@edvax.de> References: <540037DE.4030404@gmail.com> <782f4b6466266500ebcc15173fef385b@tortoiseblog.com> <5401780A.2040208@gmail.com> <20140830091803.35b9d646.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5401A28F.2060404>