Discussion:
how i use [wt] and [rt] to Copy-Paste text between two files (in Vim)
(too old to reply)
HenHanna
2024-03-02 23:20:53 UTC
Permalink
it used to be so easy to Copy-Paste text between two files with Control-C, Control-V.

THEN, 2 or 3 years ago, when i started using a new ver. of Windows,
i could no longer to this.


So i've set up the following as a Work-around

:ab wt w! ~/temp.vi
:ab rt r ~/temp.vi

So i can ..

[1] from one file, do

:.wt -- write 1 line to temp file
:.,.+5 wt -- write 6 lines to temp file


[2] optionally edit the temp file ---


[3] from another file, do the following to read (in) the temp file

:rt
Janis Papanagnou
2024-03-03 02:54:22 UTC
Permalink
Post by HenHanna
it used to be so easy to Copy-Paste text between two files with Control-C, Control-V.
In Vim it's Y and P while in between switching to another file
could be :n (if the file has been opened together with the first
file) or :r filename (if you want to ad hoc open a file).
Post by HenHanna
THEN, 2 or 3 years ago, when i started using a new ver. of Windows,
i could no longer to this.
So i've set up the following as a Work-around
:ab wt w! ~/temp.vi
:ab rt r ~/temp.vi
So i can ..
[1] from one file, do
:.wt -- write 1 line to temp file
:.,.+5 wt -- write 6 lines to temp file
[2] optionally edit the temp file ---
[3] from another file, do the following to read (in) the temp file
:rt
In Vim you'd probably like to switch to a more Vim-like way of file
processing. Open more than one file when calling Vim. Or in a Vim
session use :split somefile to load another file (then you can
toggle between your split parts of the window with Ctrl-W Ctrl-W,
doing a Y on one side and P on the other side).
Another option is to copy or append the yanked parts into a named
register; for example

"AY -- appends a line to the named register A
42G -- move to another place (here e.g. to line 42)
"A6Y -- appends 6 more lines to A
^W^W -- switch to the other split-window part (^W means Ctrl-W)
-- or use :n if you want to switch to the next file opened
"Ap -- insert the contents of A

These are just examples. There's many ways you can do such things,
depending on what fits best.

Janis
Lawrence D'Oliveiro
2024-03-03 06:51:14 UTC
Permalink
Post by HenHanna
it used to be so easy to Copy-Paste text between two files with Control-C, Control-V.
THEN, 2 or 3 years ago, when i started using a new ver. of Windows,
i could no longer to this.
Does Vim not do multi-file editing?
G
2024-03-03 09:10:32 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by HenHanna
it used to be so easy to Copy-Paste text between two files with Control-C, Control-V.
THEN, 2 or 3 years ago, when i started using a new ver. of Windows,
i could no longer to this.
Does Vim not do multi-file editing?
If you havo more then a few lines to copy or just check the differences
between two similar files "vimdiff file1 file2" is quite useful. It has
specific commands to copy from or to the other file.

G
Lawrence D'Oliveiro
2024-03-03 20:12:59 UTC
Permalink
Post by G
If you havo more then a few lines to copy or just check the differences
between two similar files "vimdiff file1 file2" is quite useful. It has
specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as you
would when editing a single file.
Janis Papanagnou
2024-03-04 07:16:34 UTC
Permalink
Post by Lawrence D'Oliveiro
In normal editors, you use the same commands for cut/copy/paste as you
would when editing a single file.
In Vi/Vim it's 'd', 'y', and, 'p' or 'P'.

Janis
G
2024-03-04 09:10:21 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the differences
between two similar files "vimdiff file1 file2" is quite useful. It has
specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as you
would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim after
all), or use the specific command if you want do things faster.

G
Lawrence D'Oliveiro
2024-03-05 23:00:02 UTC
Permalink
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as you
would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
HenHanna
2024-03-06 03:38:22 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as you
would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
in (the old Vi and) Vim , we can have 2 (or more) files open,
but i don't like to do that because it's kinda confusing.





_____________________________(a retro computer wisdom)


In software systems, it is often the early bird that makes the worm.


---------- meaning, (the sleepy programmer) ...that introduces the BUG ?


or ...... writes a computer virus ?????
Lawrence D'Oliveiro
2024-03-06 05:05:07 UTC
Permalink
Post by HenHanna
Post by Lawrence D'Oliveiro
In Emacs, you can have two files open side by side. Or even more than two.
in (the old Vi and) Vim , we can have 2 (or more) files open,
but i don't like to do that because it's kinda confusing.
Quite easy in Emacs. It also does multi-buffer editing, so you can have
more files open than you have simultaneously visible. You can even have
the same buffer visible in more than one frame/window, so you can see (and
edit) two different parts of the same file easily.
G
2024-03-06 09:33:41 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as you
would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
That's what "vimdiff" does: it automatically shows the two files side to side,
highlights the differences, folds the part that are similar if they are long,
and other stuff specific to the job of dealing with the differences between
two files. All of this can be done in normal vim, of course, it's just a fast
way of setting up for this very specific task.

G
Lawrence D'Oliveiro
2024-03-06 21:05:16 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as
you would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
That's what "vimdiff" does ...
We already gathered that. We don’t need to start Emacs in a special mode
to get that.
G
2024-03-07 09:50:04 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by Lawrence D'Oliveiro
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as
you would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
That's what "vimdiff" does ...
We already gathered that. We don’t need to start Emacs in a special mode
to get that.
We don't "need" to start vim in a special mode to get that either, but it's
faster ad easier. As I said it's just the usual vim with the options you need
to do what you want already there. If you prefer to do it the Emacs way you
can start vim with one file, load the second and give the commands to start
the "diff" mode; I just don't see why you would want to do that.

G
Janis Papanagnou
2024-03-07 13:38:22 UTC
Permalink
Post by G
Post by Lawrence D'Oliveiro
Post by Lawrence D'Oliveiro
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as
you would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
That's what "vimdiff" does ...
Actually, if all I want is edit two files with Vim I wouldn't
use vimdiff but the ordinary vim call, because vimdiff does a
lot that I usually just don't want (unless comparing files);
e.g. the coloring of file differences.
Post by G
Post by Lawrence D'Oliveiro
We already gathered that. We don’t need to start Emacs in a special mode
to get that.
We don't "need" to start vim in a special mode to get that either, but it's
faster ad easier. As I said it's just the usual vim with the options you need
to do what you want already there. If you prefer to do it the Emacs way you
can start vim with one file, load the second and give the commands to start
the "diff" mode; I just don't see why you would want to do that.
Yes, you can load a second (or third, etc) file in one step by
:split file2 or by :vsplit file3 (the latter for side by side).
No extra command necessary. If we have provided the files on
the command line already we need only :split (or :vsplit) to
get two views of the first file and :n to see the second file
in one of the split window.

But note that the other poster is likely more interested in
an argument or a flame war given that he wrote in a parallel
thread: "Emacs is the world’s most powerful editor.", so he
might not be interested in Vim facts or to learn about what
Vim actually provides beyond his prejudice or preferences.

Janis
G
2024-03-07 18:50:47 UTC
Permalink
Post by Janis Papanagnou
Post by G
Post by Lawrence D'Oliveiro
Post by Lawrence D'Oliveiro
Post by G
Post by Lawrence D'Oliveiro
Post by G
If you havo more then a few lines to copy or just check the
differences between two similar files "vimdiff file1 file2" is quite
useful. It has specific commands to copy from or to the other file.
In normal editors, you use the same commands for cut/copy/paste as
you would when editing a single file.
And in vimdiff you can use those command if you want (it is still vim
after all), or use the specific command if you want do things faster.
In Emacs, you can have two files open side by side. Or even more than two.
That's what "vimdiff" does ...
Actually, if all I want is edit two files with Vim I wouldn't
use vimdiff but the ordinary vim call, because vimdiff does a
lot that I usually just don't want (unless comparing files);
e.g. the coloring of file differences.
Yes, if I just want to edit multiple files. But for the work I do (mostly
integrating differential equations or similar stuff) I often have very similar
programs and vimdiff is very useful to check and transfer differences.
But you are right about the coloring so I have by default the usual code
coloring disabled and keep the one about differences as when I am using
vimdiff that's what I am interested in.
Post by Janis Papanagnou
Post by G
Post by Lawrence D'Oliveiro
We already gathered that. We don’t need to start Emacs in a special mode
to get that.
We don't "need" to start vim in a special mode to get that either, but it's
faster ad easier. As I said it's just the usual vim with the options you need
to do what you want already there. If you prefer to do it the Emacs way you
can start vim with one file, load the second and give the commands to start
the "diff" mode; I just don't see why you would want to do that.
Yes, you can load a second (or third, etc) file in one step by
:split file2 or by :vsplit file3 (the latter for side by side).
No extra command necessary. If we have provided the files on
the command line already we need only :split (or :vsplit) to
get two views of the first file and :n to see the second file
in one of the split window.
But note that the other poster is likely more interested in
an argument or a flame war given that he wrote in a parallel
thread: "Emacs is the world’s most powerful editor.", so he
might not be interested in Vim facts or to learn about what
Vim actually provides beyond his prejudice or preferences.
Yep, but it was fun not feeding the troll...

G
Lawrence D'Oliveiro
2024-03-07 20:18:44 UTC
Permalink
Post by G
We don't "need" to start vim in a special mode to get that either, but
it's faster ad easier.
With Emacs, we have server mode and the “emacsclient” command to add more
open files to the running instance. This can be done via a custom right-
click option in a file manager, for example.

Anthony Howe
2024-03-03 15:39:27 UTC
Permalink
Post by HenHanna
it used to be so easy to Copy-Paste text between two files with Control-C, Control-V.
With Nvi you can edit two or more files at a time.

:E edit another file (splits the screen)
:N edit next file (split the screen) :P also
^W cycles through open files.

AS I recall there are some commands or options to adjust the split screens, but
never tried.

So edit two ore more files at once; delete or yank lines from one, cycle to the
next file, and paste.

Don't recall if historical vi kept the named and numbered buffers between files,
but you could try:

"a}yy yank a paragraph into buffer a
:e other edit other file
p/P put (paste)
:e% toggle back to previous file, ^^ also toggles files.

So you can skip the need for a temporary file, unless you find that useful to
hold onto.

Also with Nvi there is unlimited undo/redo history:

u toggle undo/redo last edit (historical vi)
. repeat last, so if you undo, you can undo history (or reverse and redo).
--
Anthony C Howe
***@snert.com BarricadeMX & Milters
http://nanozen.snert.com/ http://software.snert.com/
Janis Papanagnou
2024-03-04 07:22:22 UTC
Permalink
Post by Anthony Howe
u toggle undo/redo last edit (historical vi)
. repeat last, so if you undo, you can undo history (or reverse and redo).
In Vim it's 'u' for [multiple] undos and 'Ctrl-R' for redo.

(There's also undo-trees, but I never used it.)

Janis
Loading...