Hacker News new | ask | show | jobs
by enriquto 2249 days ago
Yes, the mouse situation in tmux is catastrophic.

As much as I love tmux, I wonder what would it take that the program respects the usual copy-paste conventions like all the rest of X programs. You need to do two things, that are apparently impossible when tmux has "mouse enabled":

1. select some text in your xterm so that it gets copied

2. middle click on the xterm and your copied text (possibly from other window, web browser, whatever) gets pasted at the cursor position

This is really simple and sane behavior but it's completely impossible to achieve with the current version of tmux. I have spend much more time that I am willing to admit seriously trying to do that.

6 comments

The top reason I did start using tmux was because of how you can select text with the keyboard in copy mode (like visual in vim mode). Then I got the plugin tmux-plugins/tmux-yank which adds "y" command to copy the text. Also works with selection by mouse.

I've run this setup now for something like 5 years across multiple tmux versions and OSes (Ubuntu and Arch) without any hiccups.

But then I think tmux is a tool geared towards keyboard usage and not mouse. The mouse stuff was added because others wanted it, not because it was part of the core idea of what tmux wanted to provide. So if you go against that, you'll bang your head a little.

> The top reason I did start using tmux was because of how you can select text with the keyboard in copy mode (like visual in vim mode). Then I got the plugin tmux-plugins/tmux-yank which adds "y" command to copy the text. Also works with selection by mouse.

Sure, but this is the internal "copy mode" of tmux, and is not useful to copy text in and out of your terminal.

You can configure tmux to synchronize with the X clipboard, although it is somewhat fiddly because of how terminal emulators work. See this page: https://github.com/tmux/tmux/wiki/Clipboard

In most terminal emulators you can also use Shift (or sometimes a different modifier) to bypass application mouse mode and have the terminal emulator handle the mouse event. Of course you can't copy out of the history with this, but that is another limitation of terminal emulators.

> that is another limitation of terminal emulators.

This seems more an excuse than a cause. When the "mouse mode" of tmux is off, the copy-paste mechanism works perfectly. There is no reason why this couldn't still be the case when the mouse mode is on. For example, tmux could enable the mouse only for scrolling and resizing the panes, while keeping the correct copy paste behavior intact. But it chooses not to.

No, this is not how it works. There is no terminal emulator that offers this kind of fine-grained mouse support. tmux can either turn the mouse on and handle everything (resize, scroll, copy and paste) itself, or it can leave it off and receive no mouse events.
Then it could react to a middle-click inside a pane by pasting the text of the clipboard.
With mouse-mode on, try holding down shift to escape to regular behaviour.
No, it's not the internal "copy mode" of tmux, it's integrated with xclip (or xsel) so works via the normal clipboard I'm using in other applications too, it's basically the entire point of the tmux-yank plugin and why I shared it.

Tagline from GitHub:

> Tmux plugin for copying to system clipboard

https://github.com/tmux-plugins/tmux-yank

I could understand if you don't like tmux for other reasons (being a heavy mouse-user for example), that makes perfect sense. It's not for everyone. But if you take some time to understand why some things don't work like you expect it to (like what's the difference between a terminal emulator and tmux, what they have access to and so on) and how you could solve them, you'd avoid the issues you're describing.

But again, tmux is a tool aimed for keyboard users, not mouse. This tool doesn't fit everyone, and that's ok too. If you're willing to try it, you need to understand a few things before it'll work as you expect, otherwise your expectations will be wrong.

> I could understand if you don't like tmux for other reasons

I love tmux and I'm primarily a keyboard user. But sometimes I like to copy a short string from one window to another. Does tmux-yank allow you to middle-click paste on a tmux window? does it allow to select to copy?

Middle-click I don't know about, as I never use it. Usually I don't even have a mouse connected to my computer so I'm limited to a keyboard only. I use the provided `yank` (prefix+y by default) to copy and normal ctrl+shift+v to paste in terminal. Then in other applications I just use ctrl+v and ctrl+c normally.

For the "select to copy", all the information you need is in the GitHub repository previously linked. Here it is again: https://github.com/tmux-plugins/tmux-yank The specific section you're looking for is here: https://github.com/tmux-plugins/tmux-yank#mouse-support

It's simple for you to try it out as well, have a read about tmux plugins and you'll be up and running in a yiffy.

Also take some time to read up on terminal emulators, shells and what tmux is, as you seem to hold slightly off assumptions around where the problems you're experiencing are actually coming from. The reading and understanding will only make your personal knowledge base larger and deeper :)

No, tmux-yank only does the copying part.

To get pasting from the system clipboard, you need something like https://github.com/brennanfee/tmux-paste It will copy whatever's on the system clipboard into tmux's paste buffer, and paste it, all with a single middle-click.

I've only recently started using tmux, and all this clipboard stuff was the biggest stumbling block. But I think I've got things work well enough now.

Middle-click paste is an option offered by the terminal application. It has nothing to do with tmux
Yet tmux "captures" the middle click and decides to do nothing with it (instead of pasting the text, as correctly happens within vim).
> Then I got the plugin tmux-plugins/tmux-yank which adds "y" command to copy the text

tmux-yank copies whatever you selected to the system clipboard (xclip, clip.exe, etc.)

This is little to do with tmux and much to do with the features offered to terminal applications by terminal emulators. Both clipboard and mouse support in terminals generally is quite limited. For the clipboard, this page documents how to configure it within the limits of what is possible: https://github.com/tmux/tmux/wiki/Clipboard
That's the main problem with tmux in my experience, whenever I open an issue or a feature request on tmux github, the devs say it's a terminal issue. I then open the same issue on the terminal github and the devs there say it's a tmux problem.

Perhaps a solution could be combining a terminal and tmux into one product, so there would be no more excuses, however I don't think core devs are interested in getting a proper mouse support working in tmux.

This also bothers me. As a keyboard guy it mostly bothered me that I could not jump to the thing that I wanted to copy. I found https://github.com/schasse/tmux-jump, which works really well with https://github.com/tmux-plugins/tmux-yank
With my config a normal highlight interacts with tmux and if I hold shift it interacts with my terminal emulator. I'm using Termite, but I swear it worked the same in others like terminator and urxvt as well. I have both a local and remote tmux session and am basically exclusively using shells in tmux, so I've long since gotten used to in. This must be fairly standard, because a friend of mine uses Hexchat on Windows where a normal highlight can grab a line from IRC, but without the timestamp. Holding shift lets you grab all the actual text, timestamp included.
It works just like that if you press shift?
> It works just like that if you press shift?

My point exactly. I want to do that without pressing shift.

it works pretty well if you're in vi mode, because the same key commands are used in vim for visual mode. so you end up just getting used to scrolling that way.