0

Can I somehow copy text between two vim sessions in 2 different terminals? I use mobaxterm and can not scroll while marking text that I want to copy.

How can I do it? Edit 2 files on 2 different terminals (SSH sessions) with multiexec option and copy more text than I can see on terminal. I can not highlight it in any vim mode to copy it to my laptop notepad or other terminal SSH session window.

2
  • When copying more than screenheight, I usually use cat and select the content there...
    – Virsacer
    Mar 18, 2022 at 17:37
  • This is, in fact, kind of solution :) but maybe someone can let us know if there is any better way to do it, i tried also other vim modes but i could not select text:)
    – Kamil Bu
    Mar 18, 2022 at 19:16

1 Answer 1

0

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:

  1. 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.
  2. Open vim in the other terminal and go to the file you want to paste into
  3. Use :tabe from command mode to open a new tab
  4. Use :r /path/to/file to read the content of that file that you created in (1) into the buffer
  5. 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .