[Question] How to use Cygwin copy-paste (Windows clipboard) with mouse-mode (without shift)?

863 views
Skip to first unread message

Akira KAKINOHANA

unread,
Jul 24, 2023, 5:04:11 PM7/24/23
to tmux-users
Hello,

I've been trying to use tmux multiple times, but haven't been able to switch from GNU screen. I've tried multiple different tricks to achieve what I want, but haven't been successful. I'm wondering if someone in this group could help me out..

What I'd like to achieve is the following:
1. Use Cygwin terminal on Windows
2. SSH into a Linux (Ubuntu) node
3. Run (or attach to) tmux session in the remote Linux node
4. Within the tmux session, use the mouse-wheel to scroll up/down the the contents.
5. Also in the same tmux session, use the mouse to copy-paste functionality enabled by the Cygwin terminal. By "mouse to copy-paste", I mean..
** Simply select the text in the terminal to copy to the Windows clipboard (without pressing "shift" key)
** Click the mouse-wheel (3rd mouse-button) to paste the text in Windows clipboard onto the tmux session (again, without pressing "shift" key).

For point 4. and 5. above, I could achieve *either* of those (but not both) with/without "mouse on".

Environment:
* tmux version (in remote Linux node): 3.0a
* Cygwin terminal is configured s.t. "Middle mouse button"'s behavior is "Paste" (Under "Options > Mouse") and Mouse selection would be copied to clipboard (by checking "Copy on select" under "Options > Selection > Clipboard").

What I tried so far in $HOME/.tmux.conf:
1. set (or set-option) -g mouse on ==> needed to press "shift" to achieve 5. above
2. (with mouse off) bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send keys -M" "if -Ft= '${pane_in_mode}' 'send-keys -M' 'copy-mode -e'" ==> WheelUp on my mouse would only lead me to the previous command I typed.

I'm wondering what I'm missing.. or if it's even possible to let the point 4. and 5. above co-exist (again, without pressing "shift" key). Any help/input/suggestion will be appreciated!

Best regards,
Akira K.

Nicholas Marriott

unread,
Jul 24, 2023, 5:37:32 PM7/24/23
to Akira KAKINOHANA, tmux-users

You may be able to make tmux itself copy to the clipboard, see https://github.com/tmux/tmux/wiki/Clipboard. You will probably need to use a terminal which supports OSC 52, such as mintty.


--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/30af6ed8-7ade-4f04-8e00-60de96b113d3n%40googlegroups.com.

Akira KAKINOHANA

unread,
Jul 24, 2023, 6:30:18 PM7/24/23
to Nicholas Marriott, tmux-users
Thank you very much Nicolas for your inputs!

I'll give it a try in next few weeks and get back to this thread with whatever findings.

As for OSC 52, I seem to have been using mintty (or "mintty.exe", which is the shortcut target file from Cygwin terminal) all along, so I have have already been covered in that front..

Best regards,
Akira K.
--
Akira KAKINOHANA

Akira KAKINOHANA

unread,
Jul 25, 2023, 6:17:49 AM7/25/23
to Nicholas Marriott, tmux-users
Hello,

I've made some progress.Please consider this as an intermediate update.

Summary:
* Copying the mouse-selected text in tmux session (in remote note via ssh) to the local Windows clipboard by using MinTTY is achieved.
* Pasting the Windows clipboard text to the tmux session (with 3rd mouse-button click) has NOT been achieved yet.

What I did:
1. Follow the instruction Nicolas gave in this thread: https://github.com/tmux/tmux/wiki/Clipboard
2. In my particular case, I also needed to enable the OSC 52 in my local terminal (Cygwin-MinTTY running on local Windows). This was achieved by adding following line in my *local* $HOME/.minttyrc (please note for whoever reading this text in the future: this is one of the files that MinTTY looks at, so may not be the optimal location for you):
AllowSetSelection=yes

What is still missing:
* Above configuration allows me to copy the mouse-selected text to local Windows clipboard. However, this does not yet allow to paste the clipboard content to be pasted to the tmux session (unless you press "shift" key).

I'll try to look for ways to paste the content into the tmux session.

Best regards,
Akira K.
--
Akira KAKINOHANA

Nicholas Marriott

unread,
Jul 25, 2023, 6:48:07 AM7/25/23
to Akira KAKINOHANA, tmux-users
You should be able to read the clipboard into a tmux paste buffer using "refresh-client -l".

Nicholas Marriott

unread,
Jul 25, 2023, 6:52:25 AM7/25/23
to Akira KAKINOHANA, tmux-users
Actually mintty does not support this, so there is no way to get the clipboard from Windows to tmux except by putting it in a file, copying it to the remote host and then loading it. Or using a different terminal.

Akira KAKINOHANA

unread,
Jul 25, 2023, 8:14:47 AM7/25/23
to Nicholas Marriott, tmux-users
Hello Nicolas,
Thank you again for your input!

After going back and forth, I ended up commenting out the line with "mouse on" and added the following lines in my tmux.conf:
==
set-window-option -g mode-keys vi
bind Up copy-mode
bind -n M-Up copy-mode
==

Within the copy-mode, the mouse-wheel could still be used to move the cursor.

That's less than ideal, but I think this is so far the best solution I found for my need within tmux.

I'll be using the tmux with above config and will decide if I'd like to keep using tmux or move back to the GNU screen world..

@Nicolas :Thank you again for your help!!

Best regards,
Akira K.

--
Akira KAKINOHANA
Reply all
Reply to author
Forward
0 new messages