i have a little difficult problem with vim inside tmux inside tmux. To explain my problem, i think it's better to illustrate my setup first
+----------+ +-----------+
| vim left | | vim right | (vim 7.3)
+----------+--+ +-----------+-+
| tmux left | | tmux right | (tmux 1.6)
+-------------++ +-------------++
| ssh left | | ssh right |
+--------------++ +--------------+-+
| tmux left | | tmux right | (tmux 2.8)
+----------------+ +----------------+
| iTerm left | | iTerm right |
+----------------+-+----------------+
| Hostsystem - macOS |
+-----------------------------------+
I have two pivot monitors for source code and one iTerm per monitor. I run tmux on each of the terminals for multiplexing. I didn't like the iTerm splitting and tabbing functions, because i often work with linux workstations, servers via ssh. So i love to have tmux running everywhere for all the fancy splitting, tabbing, etc. . So i only have to remember one set of shortcuts and not many different shortcuts for different terminals (iTerm, Terminator, xterm) but for the same actions. So as i said, on every of the iTerms i start a tmux session.
Now im working on a remote server, so i connect to them via ssh in both iTerms. The left and right one.
And now, i think you can guess it, i start tmux on each ssh session, so i can split my screen directly on the server and reattach to the sessions, if there are some network connectivity issues and i lose my ssh connection.
Because i have some programming todo, i fire up vim on both terminals.
Finally everything said and explained, i come to my real problem. How can i get copy (yank) working in vim (inside tmux, inside a ssh session inside an outer tmux session inside a iTerm instance on my macOS host), so it uses my macOS clipboard.
For simplicity, i use the same .vimrc
on all of my systems. Beside some other configs i have configured that vim always uses the system clipboard instead of it's own buffers.
In the .tmux.conf
on my mac i have configured set-option -g default-command "reattach-to-user-namespace -l /usr/local/bin/bash"
to get the system clipboard working.
And as long as i'm working on my mac, everything works fine and i can copy from vim inside tmux to my system clipboard.
+--------------+ +--------------+
| vim left | | vim right | (vim 8.0)
+--------------++ +--------------+-+
| tmux left | | tmux right | (tmux 2.8)
+----------------+ +----------------+
| iTerm left | | iTerm right |
+----------------+-+----------------+
| Hostsystem - macOS |
+-----------------------------------+
But when i'm connecting to the remote server, copying stops working for me. And this is really killing me.
You can find the my .tmux.conf
on my local macOS here.
The .tmux.conf
of the remote tmux can be found here.
My .vimrc
can be found here.
I hope that helps you understanding my problem. And i hope someone can help me. I know i can copy using the iTerms-Copy function, holding the opt-key pressed while selecting with the mouse. But this is a not so optimal and only a very limited workaround.