30

Can tmux scroll speed (using a mouse wheel or touch pad) be configured?

Tmux 2.1 sort of broke scrolling (depending on your configuration), forcing me to update my config. I did that a few weeks ago.

But now I think tmux scrolls* slower than it used to. I think I read you can configure the scroll speed but I can't find any mention of that anywhere now.

* Scrolling with a mouse wheel that is. (I'm actually using a Macbook trackpad but I think it's equivalent to a mouse wheel.)

I know you can do 10C-u (with vi key bindings) to jump up 10 pages, but I'd also like to be able to just scroll fast with the mouse.

I think this is all the relevant config I personally have currently:

# Use the mouse to select panes, select windows (click window tabs), resize
# panes, and scroll in copy mode.
# Requires tmux version >= 2.1 (older versions have different option names for mouse)
set -g mouse on

# No need to enter copy-mode to start scrolling.
# From github.com/tmux/tmux/issues/145
# Requires tmux version >= 2.1 (older versions have different solutions)
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"
David Winiecki
  • 4,093
  • 2
  • 37
  • 39
  • More and more I'm thinking the scroll speed in tmux didn't change in 2.1. I think I'm confusing it with plain iTerm without tmux, where scrolling has variable velocity depending on how fast you swipe across the trackpad. Probably not something that can be fixed in tmux through configuration. I bet that would need to be a tmux feature request. – David Winiecki Mar 15 '16 at 22:25
  • It does have velocity, just not as smooth and fast as without tmux, even with a nearly empty config file. (I figure if you put enough hooks in your config it would slow things down, but that doesn't seem to be my problem.) – David Winiecki Mar 15 '16 at 22:30

6 Answers6

17

Using the tmux-scroll-copy-mode plugin should help here.

Once you've installed it, just add set -g @scroll-speed-num-lines-per-scroll 5 to your .tmux.conf.

scroll-speed-num-lines-per-scroll - Sets the number of lines to scroll per mouse wheel scroll event. The default option is 3, which was the scroll speed in tmux 2.0. Larger numbers scroll faster. To slow down scrolling slower than one line per wheel click, set the value to a decimal between 0.0 and 1.0. With a decimal value, only that fraction of wheel events will take effect. The value should be >= 0. Examples:

"3" (default) - Scroll three lines per every mouse wheel click. "1" - One line per mouse wheel scroll click (smoothest). "0.5" - Scroll one line only on every other mouse wheel scroll click. "0.25" - Scroll one line only on every fourth mouse wheel scroll click.

Community
  • 1
  • 1
domi91c
  • 1,962
  • 4
  • 23
  • 38
11

For tmux 2.4 and above, the following works for me:

bind -Tcopy-mode WheelUpPane send -N1 -X scroll-up
bind -Tcopy-mode WheelDownPane send -N1 -X scroll-down

This sets it to scroll 1 line at a time.

From the changelog - look for Changes from 2.3 to 2.4

Henry Thiemann
  • 111
  • 1
  • 3
  • Confirming this still works in tmux 2.6 (and particularly, for touch scrolling on Android, with tmux in termux). – hyperpallium Jun 19 '18 at 06:47
  • 1
    tried changing -N1 to -N10 on tmux 2.7 and it still scrolls only 1 line at a time, which is super slow for every use case. – Marek Židek Oct 06 '18 at 08:45
  • 1
    I had to use `-Tcopy-mode-vi` for mine to work because I use vi bindings in copy mode (works in tmux 3.1b) – jameh May 11 '20 at 01:32
11

I couldn't get any of the answers here working as of tmux 2.6 (last tested on 3.2), eventually figured it out so posting another answer.

This works as a stand-alone configuration file.

set -g mouse on

set-option -g status-keys vi
set-window-option -g mode-keys vi

bind-key -T copy-mode-vi WheelUpPane send-keys -X halfpage-up
bind-key -T copy-mode-vi WheelDownPane send-keys -X halfpage-down
ideasman42
  • 42,413
  • 44
  • 197
  • 320
7

I agree, the scrolling speed with only one line at the line is much too slow. You can make it jump half-pages:

bind -t emacs-copy WheelUpPane   halfpage-up
bind -t emacs-copy WheelDownPane halfpage-down

Still the half-page fix proposed here is much too fast and destroyes the impression of scrolling by replacing it with only the sensation of jumping. To make the scroll go at a custom speed you can add several send-keys commands like this:

 # Scrolling in tmux
 set -g mouse on
 bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M; send-keys -M; send-keys -M; send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M; send-keys -M; send-keys -M; send-keys -M' 'copy-mode -e; send-keys -M; send-keys -M; send-keys -M; send-keys -M'"
 bind -n WheelDownPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M; send-keys -M; send-keys -M; send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M; send-keys -M; send-keys -M; send-keys -M' 'copy-mode -e; send-keys -M; send-keys -M; send-keys -M; send-keys -M'"
xApple
  • 6,150
  • 9
  • 48
  • 49
  • Whenever working for answer kindly mention the version of tmux that your solution worked for. Or a link to the documentation. – Akash Jul 05 '18 at 12:11
  • I used tmux version 2.1. The documentation is available online. – xApple Jul 08 '18 at 06:43
2

Well here's a fairly bad solution (using vim navigation mode, note the k and j).

bind-key -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if-shell -Ft= '#{pane_in_mode}' 'send-keys 5 k' 'copy-mode -e'"

bind-key -n WheelDownPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if-shell -Ft= '#{pane_in_mode}' 'send-keys 5 j'"

Not sure yet what all the tradeoffs are, but for starters it is bad because 1, the cursor moves all over the place and 2, there is a lag when you switch directions, from scrolling up to scrolling down or vice versa, while the cursor moves to the other edge of the pane.

It does have the advantage though of a configurable velocity. Just change the 5's to adjust speed.

Full disclosure: I think that must have been heavily inspired by something I read somewhere else, because it's not very familiar now. I wish I would have credited my sources.

David Winiecki
  • 4,093
  • 2
  • 37
  • 39
  • No ! that was a good idea :) Just need to replace `k` with `C-y` and `j` with `C-e` built-in vim scroll. No need for plugin. thanks. – Hettomei Jan 23 '17 at 09:23
  • Almost perfect! Slight modification to make the scroll events go to the pane which the mouse is on even when it isn't the active pane: `bind-key -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if-shell -F -t = '#{pane_in_mode}' 'send-keys -t = H 5 k' 'copy-mode -e'" bind-key -n WheelDownPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if-shell -F -t = '#{pane_in_mode}' 'send-keys -t = L 5 j'"` Also made it so the cursor jumps to the top/bottom when scrolling to fix the lag issue. – DJ Madeira Feb 28 '17 at 19:39
-1

There's a mod for tmux allowing to specify any number of commands for 'mode' keybindings: http://ershov.github.io/tmux/

You could scroll-up or scroll-down several times or do it in a loop or even create a procedure to be executed.

For example:

bind -t emacs-copy WheelUpPane tcl { scroll-up ; scroll-up }
Yuriy Ershov
  • 354
  • 2
  • 8