Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Setup: I use iTerm2 on MacOS to connect to a remote server. The remote server runs tmux, in which I open files and edit in vim sessions.

Problem: I can't copy/paste between the remote tmux session and the local iTerm client. I can use iTerm 2's alt/option + mouse selection to select text, but this copies over multiple vim panes/tmux panes - bad.

Is there any elegant solution to make selections in tmux panes synchronize between the remote pasteboard and the local (MacOS pasteboard)? I've seen reattach-to-user-namespace, but I'm pretty certain it doesn't do what I want.

share|improve this question
3  
Is this really a tmux problem? Seems to me like you'd have the same issue in general connecting over ssh alone. –  kejadlen Apr 3 '12 at 4:30
2  
It may not be a tmux problem, but it is a workflow problem. I can't be the only one who has this exact problem - which is why I'm wondering what other people are doing to get around it. –  bhargav Apr 3 '12 at 18:33

3 Answers 3

up vote 5 down vote accepted

So, when you ssh into the server, you can use reverse tunneling so that you can talk back to your OSX machine to send it commands do pbcopy.

ssh -R 1234:localhost:22 remoteServer

Replace 1234 with any open port the remote server. Then on the remote server, you can then run:

tmux save-buffer - | ssh -p 1234 localhost pbcopy

That should connect back to OSX and send the contents of your tmux copy buffer to it. You may want to use ssh keys to prevent typing your password to your OSX machine.

If that works for, you can then create your tmux keybindings.

bind C-c run "tmux save-buffer - | ssh -p 1234 localhost pbcopy"

I should note, for this to work, you will need to turn on Remote Sharing in OSX.

Secondary Option:

Since you're using OSX, if you're also using iTerm2, you might consider installing http://code.google.com/p/iterm2/downloads/detail?name=tmux-for-iTerm2-20120203.tar.gz&can=2&q= on your servers.

It's basically a custom tmux what supports the "-C" flag. This flag hands over windows, and panes and all their splitting to iTerm2.

share|improve this answer

I think that this problem was solved in a better way:

http://seancoates.com/blogs/remote-pbcopy

share|improve this answer

A simpler method

  1. Enable XQuartz to sync clipboard
  2. Use X11 forwarding when you connect to the remote server
  3. Have a binding like in your tmux.conf: bind-key C-c run ‘tmux show-buffer | xsel -pbi'
    • where the X clipboard of your choice is after the pipe

You can do a similar binding in vim if you wish, as well

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.