From b6ee1bb67720bc02b702a3d523cc311350c44ed3 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sat, 24 Aug 2019 00:19:00 +0100 Subject: [PATCH] Emulate mouse scrolling for alternate buffers For pagers such as `less` which don't support terminal mouse features enable scrolling with the mouse wheel by emulating the behaviour using `send-keys -t= {up,down}` when in alternate (fullscreen) mode. These bindings retain the expected behaviour when using programs which do support terminal mouse events and copy-mode. --- tmux.conf | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tmux.conf b/tmux.conf index ff21d48..dd9b354 100644 --- a/tmux.conf +++ b/tmux.conf @@ -80,6 +80,32 @@ bind C-u copy-mode -u # Begin selection in copy mode with v not Space bind -T copy-mode-vi v send-keys -X begin-selection +# Enable mouse scrolling up in alternate buffers. +# If #{mouse_any_flag} is 1 the pane is running with mouse support, e.g. vim. +# If #{alternate_on} is 1 the terminal is in alternate buffer mode, e.g. less. +# If #{pane_in_mode} is 1 the pane is in copy-mode. +bind -n WheelUpPane \ + if -Ft= "#{mouse_any_flag}" \ + "send-keys -M" \ + "if -Ft= \"#{alternate_on}\" \ + \"send-keys -t= Up ; \ + send-keys -t= Up ; \ + send-keys -t= Up ; \" \ + \"select-pane -t= ; \ + if -Ft= '#{pane_in_mode}' \ + 'send-keys -M' \ + 'copy-mode -e ; send-keys -M' \" " +# Emulate mouse scrolling down in alternate buffers. +bind -n WheelDownPane \ + if -Ft= "#{mouse_any_flag}" \ + "send-keys -M" \ + "if -Ft= \"#{alternate_on}\" \ + \"send-keys -t= Down ; \ + send-keys -t= Down ; \ + send-keys -t= Down ; \" \ + \"select-pane -t= ; \ + send-keys -M\" " + # Yank to the system clipboard in copy mode if -b '[ "`uname`" = "Darwin" ]' \ 'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel \