7

So let's say I have two splits open in byobu, side by side. Furthermore, both splits have different files open in vim. I want to highlight text from one file in one split and copy it to a separate file in the other split. Any ideas?

All the results I found while searching for this talked about using the scrollback feature to copy and paste in byobu, however, that only seems to work inside a single split; not across splits.

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
Ross Allen
  • 463
  • 1
  • 5
  • 11

3 Answers3

13

Looks like I posted to quickly; seemed to have found the solution. I followed the steps found here:

http://linuxcommand.org/lc3_adv_termmux.php

I followed the steps:

shift-f3 - move to split to be copied from

alt-pgup - enter copy mode

space - start selection

cursor through desired text

enter - end selection

shift-f3 - shift focus to split to copy to

ensure receiving vim is in insert mode

alt-insert - paste selected text

Ross Allen
  • 463
  • 1
  • 5
  • 11
  • I've only used tmux and screen without byobu, so maybe I'm missing something, but I'm guessing the pasting part of this procedure could wreak havoc on Vim if you're not careful. Specifically, you need to make sure the receiving Vim is in insert mode; and you'd probably want to do `:set paste` beforehand and `:set nopaste` afterwards, so your indentation doesn't get messed up. See my answer for a nicer way. – echristopherson Sep 19 '14 at 18:58
  • You are correct that the receiving Vim has to be in insert mode. Thanks for pointing that out, I'll add it to the answer. – Ross Allen Sep 19 '14 at 22:35
7

If you are using an X Window Server, an alternative mouse-based solution to using the scrollback mode (which involves remembering a lot of keystrokes) is:

  1. Zoom in on the current pane (Shift-F11), bringing this pane to the foreground.
  2. You can now select the relevant text with your mouse without the vertical split getting in the way.
  3. Unzoom the pane (Shift-F11 again)
  4. Switch to other pane or wherever else you want to paste.
  5. Middle click paste.
nedned
  • 3,552
  • 8
  • 38
  • 41
  • This also works when accessing remotely (e.g. ssh) but, for whatever reason, I need to hold shift when selecting the text. – ostergaard Mar 30 '18 at 09:22
2

If your Vim supports the system clipboard (i.e. if vim --version output shows +clipboard), you can copy into the system clipboard from the first Vim and paste from it into the second one. This releaves us of the need to ensure the receiving Vim is in insert mode and has paste set appropriately.

The trick is to use the "+ register. So when you do the copy, prefix whatever yanking command you want to use with "+; and do likewise prefix the put command you use in the receiving Vim with it.

If you're on an X11 system, you can also use the "* register, which is X's "PRIMARY" selection buffer -- the one where text goes if you just highlight it, and which you can paste by pressing the middle button.

See :help gui-selections. GUI selection support generally requires a Vim other than "vim-tiny"; on Debian and Ubuntu the vim-gtk and vim-gnome packages are good choices.

echristopherson
  • 6,974
  • 2
  • 21
  • 31