配置tmux滚动速度

Configure tmux scroll speed

可以配置tmux滚动速度(使用鼠标滚轮或触摸板)吗?

Tmux 2.1中断了滚动(取决于您的配置),迫使我更新配置。 我几周前做了。

但是现在我认为tmux的滚动速度比以前慢。 我想我读过您可以配置滚动速度,但现在在任何地方都找不到任何提及。

*使用鼠标滚轮滚动。 (我实际上使用的是Macbook触控板,但我认为它等同于鼠标滚轮。)

我知道您可以执行10C-u(带有vi键绑定)来跳至10页,但是我也希望能够使用鼠标快速滚动。

我认为这是我个人当前拥有的所有相关配置:

1
2
3
4
5
6
7
8
9
# 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'"


使用tmux-scroll-copy-mode插件应该可以帮助您。

安装后,只需将set -g @scroll-speed-num-lines-per-scroll 5添加到.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.


对于tmux 2.4及更高版本,以下对我有用:

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

将其设置为一次滚动1行。

在变更日志中-查找Changes from 2.3 to 2.4


我同意,只有一行的滚动速度太慢了。您可以使其跳半页:

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

这里提出的半页修复仍然太快了,只用跳跃的感觉代替了滚动,从而破坏了滚动的印象。为了使滚动以自定义速度进行,您可以添加几个如下的send-keys命令:

1
2
3
4
 # 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'"


从tmux 2.6(最后一次在2.9上测试)开始,我在这里无法获得任何答案,最终弄清楚了,因此发布了另一个答案。

这可以作为独立的配置文件。

1
2
3
4
5
6
7
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


好吧,这是一个相当糟糕的解决方案(使用vim导航模式,请注意kj)。

1
2
3
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'"

尚不确定所有折衷方法是什么,但是对于初学者来说这很糟糕,因为1,光标在整个位置上移动,并且2,当您切换方向时,从上滚动到下滚动或反之亦然,这会有一个滞后移动到窗格的另一边缘。

尽管速度可配置,但它确实具有优势。只需更改5即可调整速度。

全面披露:我认为这一定是受到我在其他地方读到的东西的极大启发,因为现在还不太熟悉。我希望我会相信我的消息来源。


有一个用于tmux的mod,可以为"模式"键绑定指定任意数量的命令:http://ershov.github.io/tmux/

您可以向上或向下滚动几次,或者循环执行,甚至创建要执行的过程。

例如:

1
bind -t emacs-copy WheelUpPane tcl { scroll-up ; scroll-up }