Search code examples
terminaltmuxgnu-screen

Mouse scrolling and selection in terminal with tmux


I just switched from GNU screen to tmux 2.0 and I was surprised to discover that I can no longer scroll back the terminal history using mouse wheel and Shift-PgUp/Shift-PgDn.

This is a major turn off for me. How do I do terminal scrolling with tmux?

PS. I am aware that I can do set-window-option -g mode-mouse on to use the mouse wheel to scroll through the tmux buffer - not the terminal buffer. Another side effect of this setting is that I can no longer do mouse selection the usual way - I have to press Shift with the left mouse button.

IOW: how do I tell tmux to pass all mouse events to the terminal emulator?

PPS. Ubuntu 15.10; gnome-terminal; the scroll bars are clearly visible on the right, but under screen they indicate that only a small part of the buffer is shown, while under tmux they indicate that there is nothing to scroll.


Solution

  • I suspect your issue is actually that lines aren't being placed in the scrollback buffer at all, rather than tmux taking over the mouse and keys.

    Tmux by default uses the "alternate screen buffer" (you may notice that if you have text on the screen, then attach and detach tmux, the text will come back). Many terminal emulators will not place text that is scrolled or erased in this mode in the scrollback buffer. To disable this, do this:

    set -g terminal-overrides 'xterm*:smcup@:rmcup@'
    

    Where xterm* is whatever your terminal reports itself as in the $TERM environment variable. You may need to detach, reset the terminal, and reattach, to have it work if you set the option interactively.

    NOTE: If you use termcap instead of terminfo, use ti and te instead of smcup/rmcup.