In vim, you can use the r
command to read a file or command from somewhere else. So, what I would do in this scenario is:
- Dump what you want to copy to a file, either by redirecting the output of a command, or it's already a file so just save it.
- Open vim in the other terminal and go to the file you want to paste into
- Use
:tabe
from command mode to open a new tab
- Use
:r /path/to/file
to read the content of that file that you created in (1) into the buffer
- Then use yank/paste as normal, or use ctrl-V in command mode to do a visual select block and yank that.
Note you can pass a command to :r
as well, but you have to escape some characters, so :r! date +\%s
will get the current unix time and insert it into the file.
Lots more tips on the well known Grok Vim post.
You can also do things like turn on line numbering with :set number
, and then read specific lines from a file: :r! sed -n 147,227p /path/to/foo/foo.c
Or, use the line numbering with relative numbering (:set relativenumber
) to show you easily how many lines to yank with y
. That way you just do 37y
and then p
where you want it.