Spent too much time wonking a tmux config only realizing it was never going to work how I liked. You can't have it all with the mouse no matter your settings, there will always be a compromise. It also doesn't help that no one cites the version of tmux they wrote their configs for, nor that the configs are not backwards compatible with all versions of tmux for all settings.
It's really clunky, but I went from tmux to just opening new shell windows as needed. I need to be able to resize and scroll, selecting text and copy behavior should be exactly like mac os. Even used a tiling window manager with it for a bit, but it felt pretty restrictive so I went back to just using the cursor to move things around.
> realizing it was never going to work how I liked.
> You can't have it all with the mouse no matter your settings
> so I went back to just using the cursor to move things around.
These tools (vim, tmux, etc.) work great for mouseless setups. If you can get comfortable with a 100% keyboard control paradigm, it might work for you. I realize this might not be what you want, but if the statement "spend less time moving your hand between keyboard and mouse" resonates, it's worth revisiting.
Make your own cheatsheet for bindings you need. This way you learn faster and optimize for your own needs. Tmux is exceptional mouseless, though personally I prefer combining with mouse.
With xclip, mouse and copy/paste can work over SSH-forwarded X-sessions with C-y and Enter from copy-mode-vi so:
# For older versions of tmux:
#setw -g mode-mouse on
#set -g mouse-resize-pane on
#set -g mouse-select-pane on
#set -g mouse-select-window on
# For newer versions of tmux:
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; #send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
set -g set-clipboard on
# With xclip
bind-key -n C-y run "tmux show-buffer | xclip -selection clipboard -i >/dev/null"
#bind-key -n C-y run-shell "tmux save-buffer - | xclip -i -selection clipboard >/dev/null"
# For tmux 2.4+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'xclip -selection clipboard -i'
For Windows vcxsrv is the simplest and most fool-proof X-Windows server. Anything else on Windows may result in pain.
My preference is to reduce visual clutter in tmux by tweaking config and mostly just follow built-in bindings so workflow mostly works on standard tmux as well.
When clipboard fails between environments, sometimes multiple copy-ing, and then pasting into a text-editor helps (not a tmux issue, but clipboard-integrations).
"For Windows vcxsrv is the simplest and most fool-proof X-Windows server. Anything else on Windows may result in pain."
X servers on Windows are often a bigger cut/paste barrier than tmux. As you mention, vcxsrv seems to work better than other choices. Note there are some cut/paste/clipboard options you have to set.
I'm used to selecting only with Space, and confirming with Enter. C-b ] pastes.
This seems to be to the tmux's own clipboard. When you want to copy externally many lines, you can use C-b Z to zoom or use a lame workaround with text files opened in gedit or something. (It's a marginal use case in my experience, so I didn't bother to optimize.)
I haven't got my config to hand, but essentially I've binded leader-y and leader-p to copy and paste respectively both using the system clipboard. Since doing that tmux has been so much more useful to me.
This is the section of my config that sets up using the clipboard for tmux buffers. It won't work as is unless you're using both fish shell and Mac, but this should at least give you some good keywords to google and find documentation on how to do it for your system
You can achieve copy-pasting that isn't very different from a typical GUI without deviating too much from the defaults. If you use a sufficiently new version of tmux [1] and a terminal that supports it [2], you can just right click and drag your mouse to select and copy text into the clipboard. All you need to do is put the line 'set mouse on' in your configuration. If your terminal doesn't support this feature, you can do something like
to achieve the same thing. It also looks like you can configure copy commands to pipe to a command of your choice with the upcoming version of tmux without having to override keybindings [3].
[1]: >= 2.4, maybe?
[2]: Any terminal that supports OSC52 (e.g, iTerm2)
I use Emacs copy & paste, or readline. I don't do a lot of copy & paste between different windows though. Paste in works adequately (terminal stuffs it into keyboard buffer) but may need a reformat if the mode has autoindent, while I zoom the window (C-b z) and turn off line numbers to copy out.
If formatting is super important, I paste into a file with cat > file, and read the file into Emacs. I can do the same in reverse for a big copy out, and transfer the file.
I do these things because I often use Emacs in a ssh session instead of tramp, because I'm coming from a different OS or need to use modes with sidecar executables, e.g. enh-ruby-mode.
Tmux runs in a terminal; use `[` and `]` for my tmux buffer; and the terminals OS Copy/Paste integration when i need to get things in/out. Reading these threads I didn't realize the heartburn they felt with tmux.
For copying text I just hold down shift before click-selecting. Works fine. But if you need to select a long bit of text which scrolls beyond the screen then I use scp or rsync
shameless plug: I wrote a tool to copy text from tmux on remote host to local OS, this is often needed when you ssh into remote host, and want to copy large amount of text (e.g. more than one screen) to local OS
> You can't have it all with the mouse no matter your settings
I don't think this is correct; it's just that it's not trivial to get things working well. As you say, it depends on using an up-to-date version of tmux (and sadly, you often can't run a config made for a new version with an older version of tmux). And you'll need your terminal to be up to the task (eg. iTerm2 on macOS; not sure what the best thing on Linux would be).
This config shows some useful mouse settings, along with transparent integration with system clipboard via Clipper (even when running tmux on a remote host):
But like I said, getting it all working nicely requires a bit of work, especially if you want things to work uniformly across Vim, tmux and the shell. Once you've got it all working though, it's great. I can scroll with trackpad or mouse wheel inside and outside of Vim, click or drag to select text (and double-click to select words, triple-click to select lines) both inside and outside of Vim, I can drag tmux or Vim splits etc.
Having sad that, I rarely need or want to take my hands off the keyboard when in the terminal nowadays.
I couldnt figure out how to get the mouse behavior I liked working in the shell as well as in editors like less or nano. Id get the shell able to scroll and work well with selecting text, then Id have some archaic mouse behavior in my editors. Or I could have the editors working like they do outside of tmux, but then I lose the ability to scroll in the shell and whole tmux multipane window scrolls off screen instead. I could get into the keybinds, but I dont use vim so they are pretty ancient and foreign to me. The effort for me to learn these binds doesn't seem there compared to just moving my windows with the mouse once or twice a day.
> can scroll with trackpad or mouse wheel inside and outside of Vim, click or drag to select text (and double-click to select words, triple-click to select lines) both inside and outside of Vim, I can drag tmux or Vim splits etc.
Doesn't this kinda defeat the point of Vim? I turned on vim bindings and went through an excruciating learning process just to keep my hands on the keyboard. Moving between keyboard and mouse or trackpad was causing significant wrist issues.
For me tmux isn't about new windows, it's about keeping a session open when my ssh connection dies, or my vpn resets which causes a connection to die, or any of 100 other things that can happen. Tmux keeps my stuff going while I'm not there, and I can come back to it.
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.
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.
tmux has no direct access to the X clipboard itself. Reading the clipboard with OSC 52 is possible but it is unfortunately not widely supported by terminal emulators (you can do it with `refresh-client -l` if the terminal emulator supports it).
Or you could read it with `xclip`, `xsel` or `pbpaste`, something like:
bind -n MouseDown2Pane run "pbpaste|tmux loadb -" \; pasteb
From tmux 3.2, middle click will paste the top tmux paste buffer by default.
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.
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.
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 :)
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.
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.
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 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.
Tmux on my local machine was useless. Tmux on my server has been a godsent. Just connect and re-attach to the tmux session and you are right where you left off.
I did modify the key binds a little bit to make splitting windows and enable the mouse, but otherwise I just don’t need any more advanced behavior.
I guess different work patterns work differently for different people. I've been using tmux exclusively on my local machine (much less often on remote machines) for the last 2+ years, and it really works well for me. On a daily basis I tend to work in a lot of different contexts, so having scroll-back buffer and bash history nicely organized so I can switch from task to task, with clean restoration of the scrollback/bash history for each environment when I reboot my computer to update it is a godsend. I also like having the various parallel running tasks for a particular environment (like an ssh, log tail, commands) - all running in different panes in a single window - so I never have to go looking for them.
One change I made was forcing myself to always name a window when it gets created - that way I can usually hotkey back into an environment by its name, rather than having to go searching for windows.
I particularly like that I can use exactly the same toolset on my Mac, Windows, and Linux clients.
"Tmux on my server has been a godsent." Exactly. I let my cloud VM tmux sessions run for months. I manage other VMs and Docker containers from my tmux "command center".
I use a terminal multiplexer (happens to be screen, but could as easily be tmux) to manage local contexts. A fresh terminal in the same context is then just three keys away. The contexts drive a number of things, but most importantly I set BASH_HISTFILE so each has its own history. I love it, but of course ymmv.
I'm using tmux on server and putty to connect and it works for me. I don't really configure anything, just `set-option -g mouse on`. Mouse scroll works (emulated by tmux, but good enough for me). To copy, I'm using shift+left click drag (standard Putty hotkey), to paste I'm using shift+insert.
It's really clunky, but I went from tmux to just opening new shell windows as needed. I need to be able to resize and scroll, selecting text and copy behavior should be exactly like mac os. Even used a tiling window manager with it for a bit, but it felt pretty restrictive so I went back to just using the cursor to move things around.