tmux - scroll up/down with shift + page up/down into a pane
Solution 1
Here's a solution that should just work with your muscle memory, allowing you to use Shift+PageUp and Shift+PageDown as you would in the normal terminal.
bind -n Pageup copy-mode -u
bind -n S-Pageup copy-mode -u
bind -n S-Pagedown send-keys Pagedown
If you're using Vim, you'll want to conditionally enable this binding or it'll mess things up when you use PageUp, etc in vim inside of tmux.
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind -n Pageup if-shell "$is_vim" "send-keys Pageup" "copy-mode -u"
bind -n S-Pageup if-shell "$is_vim" "send-keys Pageup" "copy-mode -u"
bind -n S-Pagedown send-keys Pagedown
(Thanks to @mjwhitta's solution, which this refines)
Solution 2
To scroll up you can do:
bind -n S-Pageup copy-mode -u
The above doesn't appear to work on a Mac, so I tested with:
bind -n S-Up copy-mode -u
As far as I can tell, after pressing S-Up, you can continue to use S-Up or just page-up to keep scrolling up. You can use page-down to scroll down. These aren't exactly the key-bindings you were looking for, so I apologize. This should get you closer to your goal I hope.
EDIT:
I just tested with:
bind -n Pageup copy-mode -u
and this allows you to use just page-up and page-down.
Solution 3
Yes I know this question is old but it's not that far down in the google results and I just spent a lot of time to find out how to do it simply because almost no google result contained an answer, only questions.
AFAIK only one pane scrolls when in copy mode. To go into copy mode you can use prefix-[
and then scroll using C-up
and C-down
or you can set your own keybindings (in the config file) which in emacs-mode looks like this:
bind-key -t emacs-copy -n S-PPage halfpage-up
bind-key -t emacs-copy -n S-NPage halfpage-down
This will set the key combinations Shift+PageUp and Shift+PageDown to scroll half a page up respectively down when in copy mode. When you're using vi-mode you need to change it to something like this:
bind-key -t vi-copy -n S-PPage halfpage-up
bind-key -t vi-copy -n S-NPage halfpage-down
Now if you want to enter copy mode "automatically" and don't want to use prefix-[
you could add the following line to your config file:
bind-key -t root -n S-PPage copy-mode -u
This would open copy mode and scroll a (full) page up when pressing Shift+PageUp in Edit-Mode (default-mode). To only open copy mode without already scrolling up a page, simply omit the -u
.
And if you want to scroll a full page up/down or just a line you can use the keywords page-up
, scroll-up
or use one of the commands
tmux list-keys -t vi-copy
tmux list-keys -t emacs-copy
to see a complete list of options to use and default keybindings.
Related videos on Youtube
user1610662
Updated on September 18, 2022Comments
-
user1610662 over 1 year
I would like to be able to scroll up/down into a given pane with the same keybinding that xterm does, i.e SHIFT + Page Up/Down.
For example, if the tmux window is divided into 2 vertical panes, I could scroll on one of the two with keyboard while the other one does not scroll.
Is it possible ?
Here's my tmux.conf :
set -g status off set -g prefix C-o unbind C-b bind C-o send-prefix # settings ------------------------------------------------------------- setw -g utf8 on setw -g xterm-keys on set -g default-terminal "screen-256color" set-option -g set-titles on set-option -g set-titles-string '[#S:#I #H] #W' # auto-set window title setw -g automatic-rename setw -g aggressive-resize on # vim keybinds set-option -g status-keys vi set-window-option -g mode-keys vi # scroll inside the current pane #bind-key k page-up #bind-key l page-down # mouse set -g mode-mouse on setw -g mouse-select-window on setw -g mouse-select-pane on # scrollback buffer n lines set -g history-limit 100000 # fixes shift-pageup/shift-pagedown set -g terminal-overrides 'xterm*:smcup@:rmcup@' set -g visual-activity on # faster key repetition set -s escape-time 0 # activity alert setw -g monitor-activity on set -g visual-activity on # alt+directions navigates through panes bind-key -n M-left select-pane -L bind-key -n M-right select-pane -R bind-key -n M-up select-pane -U bind-key -n M-down select-pane -D
-
kindrobot almost 8 yearsWhile
bind -n Pageup copy-mode -u
does allow me to press PgUp to enter copy-mode and scroll up, I can't then use PgUp to keep scrolling up. -
mdip over 5 yearsI'm not sure if it's the version of
tmux
I'm running or not, but the-t
parameter is not recognized (however, -T works) Possible typo? -
79E09796 almost 5 years+1 but
bind -n Pageup if-shell "$is_vim" "send-keys Pageup" "copy-mode -u; send-keys Pageup"
was required to get Pageup to continue scrolling up on multiple presses. -
smido over 4 yearsMost probably a typo but also not it doesn't make sense together with
-n
, as this is a shortcut for-T root
-
SRobertJames over 2 yearsWorks well! How do you exit scroll mode afterwards, so that you can type in the term normally?