Copy/Paste from tmux

334 views
Skip to first unread message

Eric Swenson

unread,
Jun 6, 2023, 3:50:20 PM6/6/23
to tmux-users
I run multiple services on a VPS under tmux.  When I SSH to my VPS and attach to a tmux window, I'm able to copy/paste successfully to other windows/applications under macOS, but not under Ubuntu. I've followed various guides that purport to allow copy/paste under Ubuntu (22.04 LTS), but none has worked for me.  How can I enable this?  For example, in a tmux window, I might encounter a URL.  Using the mouse, I get a popup offering to allow me to "copy the url", and selecting this option, and going to another GNOME Terminal window, or to some application like a browser, I'm unable to paste the URL.  The same occurs for arbitrary text.

I can even factor SSH out of the picture. If I simply start up a Terminal session, using bash as my shell, and then start tmux, anything I attempt to copy using the mouse will not end up on the system clipboard, and thus an attempt to paste will either result in nothing being pasted, or perhaps the last non-tmux clipboard copied text being pasted.

I've tried installing xsel, and binding MouseDragEnd1Pane to use it (as described in this article:  https://github.com/tmux/tmux/wiki/Clipboard.  This didn't change anything.

Help?

-- Eric

Nicholas Marriott

unread,
Jun 6, 2023, 4:46:33 PM6/6/23
to Eric Swenson, tmux-users
You could try installing a terminal which supports OSC 52 and setting that up (it may work out of the box).



--
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/acf636b2-324a-48da-aa43-2a561f1f4dc8n%40googlegroups.com.

Eric Swenson

unread,
Jun 6, 2023, 4:49:37 PM6/6/23
to Nicholas Marriott, tmux-users
Thanks. Google searches for "OSC 52" AND terminal AND "Ubuntu 22.04 LTS"
don't turn up anything. Do you know that such a terminal program exists
for Ubuntu 22.04 LTS?

-- Eric

Nicholas Marriott

unread,
Jun 6, 2023, 4:50:22 PM6/6/23
to Eric Swenson, tmux-users
Read the clipboard page on the tmux wiki.

Eric Swenson

unread,
Jun 6, 2023, 4:56:31 PM6/6/23
to Nicholas Marriott, tmux-users

I did.  That was where I found all the references to binding keys for xsel. 

However, I looked at it again, and found the section where it said that xterm supported OSC 52. So I configured the required:

XTerm*disallowedWindowOps: 20,21,SetXprop
in my ~/.Xresources, and fired up xterm. It has the same problem. Nothing I copy out of my tmux session makes it to the system clipboard. 

-- Eric

Nicholas Marriott

unread,
Jun 6, 2023, 4:57:13 PM6/6/23
to Eric Swenson, tmux-users
How are you copying from tmux?

Eric Swenson

unread,
Jun 6, 2023, 5:03:04 PM6/6/23
to Nicholas Marriott, tmux-users

I'm trying to simply highlight the text with the mouse -- which does highlight, and then use the "Copy ..." contexts menu that comes up to copy to the system clipboard.  This works fine on my Mac -- just not on Linux.

I've also tried entering copy mode, selecting the start and end via keyboard -- and that also doesn't work.

-- Eric

cheyrn

unread,
Jun 6, 2023, 5:09:22 PM6/6/23
to tmux-...@googlegroups.com

Have you tried setting up the tmux-yank plugin? That is what I am using to copy to the clipboard, together with xsel.

--
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.

Nicholas Marriott

unread,
Jun 6, 2023, 5:13:26 PM6/6/23
to Eric Swenson, tmux-users
tmux doesn't work like you describe. If you select text with the mouse it should copy as soon as you release. The only copy menu items are to copy a word or a line. Are you sure you are actually copying using tmux and not the terminal's own tools? Do you see the text you copied if you enter buffer mode or use list-buffers?

You will not be able to get xsel or xclip working from another host without X11 forwarding, you could try that but OSC 52 is usually easier.

If you are sure you are copying using tmux, then:

- Did you restart X or reload the .Xresources with xrdb before starting xterm?

- Did you follow the steps in the clipboard page quick start section to make sure everything is set up properly?

Eric Swenson

unread,
Jun 6, 2023, 5:15:06 PM6/6/23
to tmux-...@googlegroups.com

No I haven't.  I'll look for that plugin and try it.  Thanks.

I'm wondering, however, whether my issue has something to do with SSH (remote access).  I just tried an experiment:

From xterm on my Ubuntu 22.04 LTS system, I proved to myself that X windows copy/paste worked fine. Then I started up tmux, and tried selecting with mouse and pasting in the tmux window. That worked fine too.  Then I exited tmux, and SSH'ed to my VPS.  I tried X windows style copy/paste, and this worked fine (not running tmux remotely yet).  Then I started up tmux (the use case that I need to get working) from my SSH session on the VPS.  Now, copy/paste dosn't work any more.  tmux enters copy mode when I use the mouse, highlights the text when I select it with the mouse, gives me a popup menu that offers to copy the line, and when I select that menu item and release the mouse, and try to paste the result, I get nothing.

So it is the combination of SSH and tmux that prevents tmux from letting me copy/paste.  Does that suggest anything?

-- Eric

Eric Swenson

unread,
Jun 6, 2023, 6:26:33 PM6/6/23
to tmux-...@googlegroups.com

So I tried this again after verifying that I was accessing my VPS from an xterm window, with "ssh -X", and that my tmux on the VPS had the proper set-clipboard setting (external), that "tmux info | grep Ms" showed the proper string, I bound copy-mode C-w as such:

bind -Tcopy-mode MouseDragEnd1Pane send -X copy-pipe-and-cancel 'xsel -i'

and things are acting differently -- although not yet what I want.  First of all, when I'm running irssi in the tmux session, I can select a URL (the use case I want to work) with the mouse, and have it immediately get copied. I can then immediately paste it with a middle-mouse click in tmux.  I can also (much more importantly) go to a Terminal window on my local Ubuntu machine, and use the middle-mouse button to paste it in the shell.  However, what I really want to be able to do is to paste that URL into a browser address bar.  That doesn't work. A yucky workaround is to paste the URL into a terminal shell, and then use Control-Shift-C to copy it to the *real* system clipboard, and then I can paste it into the address bar of the browser.

But it shouldn't be this difficult.  On macOS, I can simply select the URL (in the irssi/tmux/ssh remote session) and paste it directly into my browser's address bar. 

Given that I am now managing to get the string copied such that I can paste it in a terminal shell (didn't use to be able to do that, so progress), why can X paste it into the GNOME Terminal, but not make it to whatever system clipboard is necessary to allow me to paste it into a browser (Brave, like Chrome) browser?

-- Eric

Eric Swenson

unread,
Jun 6, 2023, 6:27:22 PM6/6/23
to Nicholas Marriott, tmux-users

I forgot to send this before the last message I sent to the list:

Ah. There is some interference here. The use case I was *really* trying to get working was copying text from an irssi client running within a tmux session on a remote host accessed with ssh.

It would appear that the popup is coming from irssi.  If I use another tmux window (not running irssi), I can select text with a mouse, and have it immediately "copied" (somewhere) when I release.  However, it still never makes it to my system clipboard (local system). 

Let me re-check everything in my tmux configuration on the remote system. I'd really not like to be required to use xterm and X (as well as X forwarding over SSH), but I will do that if necessary. 

<I've done the above and sent the results in my  previous message to the list>

-- Eric

Scott Rochford

unread,
Jun 6, 2023, 10:58:42 PM6/6/23
to Eric Swenson, Nicholas Marriott, tmux-users
Dealing with 3 clipboards here... even ignoring the tmux clipboard, the X vs Gnome (terminology? - the one you refer to as the *real* system clipboard) clipboard confusion has been a bad Linux user experience problem for a long time now.  Are you aware that you can usually use middle-mouse-click to paste from the X clipboard directly?

--
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.

Eric Swenson

unread,
Jun 6, 2023, 11:04:39 PM6/6/23
to Scott Rochford, Nicholas Marriott, tmux-users
I am aware how f middle-mouse paste, but I didn’t actually try that to paste the copied URL into the browser address bar — I just tried C-v. I’ll give middle-mouse a try in the address bar and report on whether that did anything different. 

I had thought, however, that whether I used C-v (in the browser) or C-Shift-v in the shell or middle-mouse, shouldn’t matter — that they all pasted from the system clipboard.

— Eric (KC6EJS)

On Jun 6, 2023, at 19:58, Scott Rochford <annihi...@gmail.com> wrote:



Trey Blancher

unread,
Jun 6, 2023, 11:32:42 PM6/6/23
to Scott Rochford, Eric Swenson, Nicholas Marriott, tmux-users
Eric,

I'd like to add that X.org has the concept of two "clipboards," the copy buffer
which in many GUI programs you put data into with Ctrl-C after making your
selection (or through a context menu, e.g. Edit/Copy, Edit/Cut, etc.). It also
has the concept of a selection buffer, that gets populated whenever you
highlight (select) text with your mouse (with no other keyboard or menu events).
This selection buffer you paste with middle click usually.

Now, depending on your window manager (WM) or Desktop Environment (DE, sounds
like you're using GNOME), you can combine these buffers into one (essentially
telling your environment to put selected text into the copy buffer, which gets
populated whenever you select text). That may also be at play here (I'm not
sure what GNOME defaults to for this nowadays).

Typically highlighted text from mouse events is handled solely within your local
terminal emulator. tmux shouldn't have any bearing on this usually unless
you've enabled mouse mode (you've witnessed firsthand how difficult that can be
with X11 Forwarding). You stated your problem seems to be with irssi in a
remote tmux window; you're likely bitten by the common problem of URLs being
wrapped within irssi (so you can't just click the link to launch the URL in your
configured web browser; the URL will be incomplete). I haven't used irssi in a
long time, but weechat (another CLI IRC client) you can issue the '/window bare'
command to load the channel buffer into a pager (like less or more) where the
terminal emulator sees the entire URL (i.e., not broken up by wrapping) so you
can merely click on it rather than copying it somewhere else and navigating that
cumbersome way. I'd see if you can configure irssi similarly. I also use a
similar feature in mutt/elinks to solve the same problem in email.

IIRC, irssi was missing a lot of features the last time I tried it, a lot of
common IRC functionality had to be added manually by the user.

My $0.02. Hope this helps.

Trey Blancher
tr...@blancher.net

On Wed, Jun 07, 2023 at 12:58:27PM +1000, Scott Rochford wrote:
> Dealing with 3 clipboards here... even ignoring the tmux clipboard, the X
> vs Gnome (terminology? - the one you refer to as the *real* system
> clipboard) clipboard confusion has been a bad Linux user experience
> problem for a long time now.  Are you aware that you can usually use
> middle-mouse-click to paste from the X clipboard directly?
> >> On Tue, 6 Jun 2023, 22:03 Eric Swenson, <[2]er...@swenson.org> wrote:
>
> >>> I'm trying to simply highlight the text with the mouse -- which does
> >>> highlight, and then use the "Copy ..." contexts menu that comes up to
> >>> copy to the system clipboard.  This works fine on my Mac -- just not
> >>> on Linux.
>
> >>> I've also tried entering copy mode, selecting the start and end via
> >>> keyboard -- and that also doesn't work.
>
> >>> -- Eric
>
> >>> On 6/6/23 13:56, Nicholas Marriott wrote:
>
> >>>> How are you copying from tmux?
>
> >>>> On Tue, 6 Jun 2023, 21:56 Eric Swenson, <[3]er...@swenson.org> wrote:
>
> >>>>> I did.  That was where I found all the references to binding keys
> >>>>> for xsel. 
>
> >>>>> However, I looked at it again, and found the section where it said
> >>>>> that xterm supported OSC 52. So I configured the required:
>
> >>>>XTerm*disallowedWindowOps: 20,21,SetXprop
>
> >>>>> in my ~/.Xresources, and fired up xterm. It has the same problem.
> >>>>> Nothing I copy out of my tmux session makes it to the system
> >>>>> clipboard. 
> >>>>> -- Eric
> >>>>> On 6/6/23 13:50, Nicholas Marriott wrote:
>
> >>>>>> Read the clipboard page on the tmux wiki.
>
> >>>>>> On Tue, 6 Jun 2023, 21:49 Eric Swenson, <[4]er...@swenson.org>
> >>>>>> wrote:
>
> >>>>>>> Thanks. Google searches for "OSC 52" AND terminal AND "Ubuntu
> >>>>>>> 22.04 LTS"
> >>>>>>> don't turn up anything. Do you know that such a terminal program
> >>>>>>> exists
> >>>>>>> for Ubuntu 22.04 LTS?
>
> >>>>>>> -- Eric
>
> >>>>>>> On 6/6/23 13:46, Nicholas Marriott wrote:
> >>>>>>> > terminal which supports OSC 52
>
> > --
> > 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 [5]tmux-users+...@googlegroups.com.
> > To view this discussion on the web, visit
> > [6]https://groups.google.com/d/msgid/tmux-users/3720337d-f987-aae6-999e-a9419f34a2e1%40swenson.org.
>
> --
> 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 [7]tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit
> [8]https://groups.google.com/d/msgid/tmux-users/CAAqsAtTnQBJNC626RKpHWRO2s-rjK96vqyTX0JPj%2B1wicWA7Zw%40mail.gmail.com.
>
>References
>
> Visible links
> 1. mailto:er...@swenson.org
> 2. mailto:er...@swenson.org
> 3. mailto:er...@swenson.org
> 4. mailto:er...@swenson.org
> 5. mailto:tmux-users+...@googlegroups.com
> 6.
> https://groups.google.com/d/msgid/tmux-users/3720337d-f987-aae6-999e-a9419f34a2e1%40swenson.org?utm_medium=email&utm_source=footer
> 7. mailto:tmux-users+...@googlegroups.com
> 8.
> https://groups.google.com/d/msgid/tmux-users/CAAqsAtTnQBJNC626RKpHWRO2s-rjK96vqyTX0JPj%2B1wicWA7Zw%40mail.gmail.com?utm_medium=email&utm_source=footer

Eric Swenson

unread,
Jun 7, 2023, 12:06:29 AM6/7/23
to Trey Blancher, Scott Rochford, Nicholas Marriott, tmux-users
Thanks very much, Trey. A lot of good information here — let me try to take advantage of it to find a solution.

— Eric (KC6EJS)

> On Jun 6, 2023, at 20:32, Trey Blancher <tr...@blancher.net> wrote:
>
> Eric,

Nicholas Marriott

unread,
Jun 7, 2023, 1:28:59 AM6/7/23
to Eric Swenson, tmux-users
If it can be pasted in xterm but not in a browser you are probably setting the wrong clipboard. You can use xsel to view the different clipboards to see which it is going to (and to copy between them).

You can configure xterm's default clipboard, look at the selectToClipboard resource and probably others.

If you use both xsel and OSC 52 in tmux they are likely to interfere with each other so best pick one.

If you have complaints about X probably best take them to the X lists, although no doubt they have heard this before.


Tobias Damisch

unread,
Jun 7, 2023, 7:18:04 AM6/7/23
to tmux-...@googlegroups.com
Just because I think it hasn't been mentioned yet:
If you want to copy text from a shell into the system clipboard,
try highlighting it with the mouse and copy it using Ctrl+Shift+c.
This should typically work. I have mouse mode disabled in tmux,
so highlighting with mouse is something the terminal handles in my setup.


> Gesendet: Mittwoch, 07. Juni 2023 um 06:06 Uhr
> Von: "Eric Swenson" <er...@swenson.org>
> An: "Trey Blancher" <tr...@blancher.net>
> Cc: "Scott Rochford" <annihi...@gmail.com>, "Nicholas Marriott" <nicholas...@gmail.com>, "tmux-users" <tmux-...@googlegroups.com>
> Betreff: Re: Copy/Paste from tmux
> 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/F516F9F1-9BC4-4966-AC51-3AE7A9C8F822%40swenson.org.
>

Eric Swenson

unread,
Jun 7, 2023, 10:37:14 AM6/7/23
to Tobias Damisch, tmux-...@googlegroups.com
I’m wondering if having mouse mode enabled in tmux is what is screwing things up for me. It would prevent, for example, being able to highlight and use Carl-Shift-C to copy. I’ll try disabling it and see what happens.

However, the thing to note in my situation is this: this all works as expected (even with mouse mode enabled in the remote tmux) under macOS. It is just failing in Ubuntu/GNOME. This suggests, to me, that it is not my tmux config that is the problem or needs tweaking. Maybe this is a GNOME issue?

— Eric (KC6EJS)

> On Jun 7, 2023, at 04:18, Tobias Damisch <tobias_...@gmx.at> wrote:
>
> Just because I think it hasn't been mentioned yet:
> To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/trinity-eef71fc0-3cb5-4b1a-9f4f-093ab6d5b3e2-1686136681001%403c-app-gmx-bap21.

Eric Swenson

unread,
Jun 7, 2023, 11:52:03 AM6/7/23
to Nicholas Marriott, tmux-users

If would appear that all my issues were due to my using "set -g mouse on" in my .tmux.conf on the remote computer. Turning off mouse mode allows me (now) to copy URLs and other text from my irssi tmux session and paste them in the command line or in the browser with no issues.

Thanks all for your help on this matter. I will learn to deal without mouse mode! 

-- Eric

Reply all
Reply to author
Forward
0 new messages