Moving Text In vi(1) To Another File

Jamie Griffin griffin8j at gmail.com
Sat Aug 30 07:06:53 UTC 2014


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


More information about the freebsd-questions mailing list