Scroll shell output with mouse in tmux

Mouse scrolling doesn't work in tmux the way it works when I run shell without tmux (in Gnome Terminal). It seems tmux sends mouse scroll events as if I pressed Up/Down keys. But I want it to scroll though the shell output history. Is there a way to make tmux work like this?

Note: I know how to scroll with the keyboard (thanks to another question here).

I tried mouse scrolling in two versions of tmux:

  • 0.8-5hardy1 (on Ubuntu 8.04 (Hardy Heron))
  • 1.3-1 (on Ubuntu 10.10 (Maverick Meerkat))

Solution 1:

To scroll within history of the output You would use ^b + [ You can then use M+V to page up and ^V to page down. I don't know if You can use the real PgUp and PgDown though. My terminal does not send these keys to the tmux. Instead it scrolls itself and not the tmux history.

To exit the copy mode, press ESC

To use your mouse in this mode (called copy mode) press ^b + : and enter following:

setw -g mouse on

Note: In tmux < 2.1, the option was named mode-mouse, and not mouse

Now when You change to the copy mode you can use your mouse to scroll through it. You can put this command in your ~/.tmux.conf if You want so it loads every time You run tmux.

Update: As of tmux 1.5 this option makes using the scroll wheel automatically switch to copy mode and scroll back the tmux scrollback buffer. It is not necessary to first hit Ctrl-B + [ any more. Scrolling back down to the prompt also ends copy mode automatically.

Solution 2:

There are some changes for Tmux 2.1

  • Mouse-mode has been rewritten. There's now no longer options for:

    • mouse-resize-pane
    • mouse-select-pane
    • mouse-select-window
    • mode-mouse

    Instead there is just one option: 'mouse' which turns on mouse support entirely.

That would be

set -g mouse on
# to enable mouse scroll, see https://github.com/tmux/tmux/issues/145#issuecomment-150736967
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"