26

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

5 Answers 5

19

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)

3
  • +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.
    – 79E09796
    Commented Aug 1, 2019 at 9:42
  • Works well! How do you exit scroll mode afterwards, so that you can type in the term normally? Commented Nov 23, 2021 at 22:05
  • I just press Enter and tmux just sends me back to the prompt at the bottom of the terminal.
    – Pierre
    Commented Sep 7, 2023 at 9:46
9

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.

1
  • While 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.
    – kindrobot
    Commented Jun 23, 2016 at 0:44
6

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.

2
  • 2
    I'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?
    – mdip
    Commented Jan 17, 2019 at 15:16
  • Most probably a typo but also not it doesn't make sense together with -n, as this is a shortcut for -T root
    – smido
    Commented Nov 22, 2019 at 8:31
0

To do specifically what the question asked, with a current version of tmux, you want:

bind -n S-Pageup copy-mode -eu
bind -n S-Pagedown send-key -X page-down

This differs from @jack-senechal's answer in two important ways:

The -e argument to copy-mode tells it to exit copy-mode if you scroll down to the bottom, so you don't have to exit out of it manually if you end up scrolling all the way down.

Using send-key -X instead of send-key means that the page-down will only be sent to copy-mode, ensuring that the behavior is the same as you get on Xterm, or with a libvte based terminal emulator. (Such as gnome-shell or the like.)

This works on terminals which send a unique sequence for shift-page up/down compared to page up/down, and which use the sequence specified by terminfo.

So: libvte based terminals (gnome-terminal and company), kitty, konsole, foot, and terminology.

But not: xterm, pangoterm, cool-retro-term, or qterminal.

Sadly for users of terminals in the latter group, there really isn't much tmux can do when it's not getting a key sequence that it recognizes as shift-page up/down. Though the other answers are somewhat useful for those cases.

0

here's my config for Shift-scrolling in tmux:

bind -n S-Up copy-mode -e \; send-keys -X scroll-up
bind -n S-Down copy-mode -e \; send-keys -X scroll-down
bind -n S-Pageup copy-mode -e \; send-keys -X halfpage-up
bind -n S-Pagedown copy-mode -e \; send-keys -X halfpage-down

it enters and exits copy-mode automatically. Also it scrolls half page which i find more convenient

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .