Copying and pasting between tmux panes containing vim instances over SSH in Terminal.app
I use vim to develop Perl code on a remote Linux box running Debian Jesse. The machine is a virtual machine running in VirtualBox. I use ssh and then issue a vim <file>
command to start editing the file.
I've been experimenting with tmux on the remote machine to see how I like it. But I cannot for the life of me figure out how to copy and paste text between vim instances in two different tmux panes. I'd prefer to be able to use both the mouse and vim-like keystrokes (yy
, dd
p
) to do this.
I've tried just about every recommendation out there for trying to get this to work but I haven't gotten anywhere. I'm running El Capitan. Is there a definitive answer out there for getting this to work?
Solution 1:
A better way to do it is save the selection in a temporary file and use tmux load-buffer
command to load it into the paste buffer, and then C-b ]
to paste.
Otherwise you may have problems with long text lines that don't fit into the screen. Also, tabs might not be preserved and long lines may be broken down.
I have to mention another (easier) way to do it without any additional files.
There's a mod for tmux adding more flexible scripting capabilities: http://ershov.github.io/tmux/ (I'm the author)
It allows you to copy and paste without using any temporary files:
- Copy selection in vim
- In vim, type
:!tmux tcl pbcopy "^R%"
this will put the vim's paste buffer into tmux's one - In tmux, in another pane use
^B ]
to paste.
You probably want to use :set paste
in vim.
And if you do it frequently, you can automate the step 2 and bind it to a keypress in vim.