Moving Text In vi(1) To Another File
freebsd at edvax.de
Fri Aug 29 08:47:31 UTC 2014
On Fri, 29 Aug 2014 09:20:46 +0100, 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?
The "best" utility is the one you're most familiar with,
regarding the particular task.
When I read your task, I immediately thought: "Well, that
sounds like a job for joe." (joe = Joe's own editor, a
WS-inspired advanced text editor). I'd work like that:
% joe input.txt
move cursor to text segment you want to copy
cursor and page scroll keys work as expected
^KB (block begin) -> where to begin
^KK (block end) -> where to stop
begin and end can be set independently (!)
without losing the selection
creates new file or opens existing file
if existing file: move cursor to where you want
the segment to be copied at
^KC (block copy)
^KX (save and exit)
file out1.txt will be closed, you're back at input.txt
repeat from ^KB/^KK step as needed
^C Y (exit without saving - refers to input.txt file)
Note that you can use ^KN (next) and ^KP (prev) to switch
between the files you're editing. If you want to move a block
of text rather than copying it, use ^KM instead of ^KC; this
changes the input file. At the end of the session, use ^KX to
save it, or ^C Y to lose the changes.
You can surely solve the task with vi, but my use of vi is too
limited in order to give you the required advice, that's why I
suggested a different editor. It's not that vi cannot do it.
It's just that I can't remember how, at the moment. Still I
hope this comment will be helpful for you. :-)
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions