1973

How do I scroll with either the keyboard or mouse? The tmux man page indicates one must enter copy-mode to scroll. Is there a way to quickly scroll without manually entering copy-mode?

Mateen Ulhaq
  • 3,558
chadoh
  • 19,899

15 Answers15

2372

Ctrl-b then [ then you can use your normal navigation keys to scroll around (eg. Up Arrow or PgDn). Press q to quit scroll mode.

Alternatively you can press Ctrl-b PgUp to go directly into copy mode and scroll one page up (which is what it sounds like you will want most of the time)

In vi mode (see below), you can also scroll the page up/down line by line using Shift-k and Shift-j (if you're already in scroll mode). Unshifted, the cursor moves instead of the page.

Excerpts from the man page:

tmux may be controlled from an attached client by using a key combination of a prefix key, ‘C-b’ (Ctrl-b) by default, followed by a command key.

 The default command key bindings are:

[           Enter copy mode to copy text or view the history.

Function                     vi              emacs
--------                     --              -----
Half page down               C-d             M-Down
Half page up                 C-u             M-Up
Next page                    C-f             Page down
Previous page                C-b             Page up
Scroll down                  C-Down or C-e   C-Down
Scroll up                    C-Up or C-y     C-Up
Search again                 n               n
Search again in reverse      N               N
Search backward              ?               C-r
Search forward               /               C-s

Plus a bunch more. Note that you have to press C-b twice if you use that for page up since C-b is bound as the command key. See the man page for information on prefacing a copy mode command with a repeat count.

You can set the key binding mode using Ctrl-b, then

:set-window-option mode-keys emacs

or vi.

  • 22
    I think C-b = is choose-buffer by default. Did you mean C-b [ (which is copy-mode by default)? Also you can also use C-b PageUp to start copy-mode directly on the previous page (very handy when you know what you want to view/copy has already scrolled off the current page). – Chris Johnsen Nov 11 '10 at 05:55
  • 1
    @Chris: In my tmux 0.8 (and its man page), C-b = is scroll-mode. Apparently, newer versions have dropped that. – Dennis Williamson Nov 11 '10 at 11:53
  • 1
    Ahh, that explains it. I think I started with 1.1 which was already after scroll-mode had been subsumed. The OP says ‘only two instances of the word "scroll" [in the man page]’, so the version is probably one without scroll-mode. – Chris Johnsen Nov 11 '10 at 12:22
  • 5
    Correct, my tmux has no scroll-mode. You need to C-b [ to enter copy mode and then use either the emacs or vi key-bindings to scroll around. This seems like a lot of steps just to scroll, but the benefits of tmux still outweigh these annoyances. I'm on a macbook and there is no PageUp key :-. (Also, how do I make keys with markdown like you did, Dennis?) – chadoh Nov 11 '10 at 17:11
  • 52
    @chadoh: Try these on your Macbook: Home: fn-LeftArrow; End: fn-RightArrow; Page Up: fn-UpArrow; Page Down: fn-DownArrow. To make keycaps: <kbd>Ctrl</kbd> – Dennis Williamson Nov 11 '10 at 18:43
  • 6
    on macbook, the fn+up goes straight to terminal app and never hits tmux – Tyler Apr 11 '11 at 17:57
  • 17
    On a macbook if you're in scroll mode you can use fn+Shift+LeftArrow to scroll up a page. – Nick Hammond May 18 '13 at 17:51
  • With vi mode-keys you can also use it's typical: C-y and C-e to scroll up/down line by line – wik Jul 29 '13 at 12:07
  • @chaiyachaiya's answer is much better (If you can bear to reach for the mouse) – Jonathan Hartley Nov 04 '13 at 09:44
  • 2
    To escape from scroll mode, press Escape or Q. Don't get stuck like I did :) – Graham Perks Feb 04 '15 at 01:59
  • Isn't there a better way than just up and down arrows to scroll tmux? Like batch scrolling as in ctrl+b similar to VIM? – Charlie Parker Jan 26 '16 at 00:34
  • 1
    @CharlieParker: I've expanded my answer to include some navigation key bindings. Note that you can use numeric count prefixes like you would in vim so (set to vi key bindings) you could press 2 then PageUp (or Ctrl-b (twice)) and you'd move up two screen fulls. – Dennis Williamson Jan 26 '16 at 00:52
  • 2
    So much hassle just to accomplish basic stuff - why UI has to be so poor? – Dima Knivets Apr 07 '16 at 12:22
  • Is Shift-j and Shift-k line by line scrolling enabled by default? It seems like it is on my machine. – mbigras Apr 05 '17 at 16:13
  • @mbigras: It seems to be. – Dennis Williamson Apr 05 '17 at 16:16
  • @DennisWilliamson does that mean tmux is in vi mode by default? Or does it only have some of the functionality? Line by line scrolling in this case. – mbigras Apr 05 '17 at 16:18
  • @mbigras: From the man page: "mode-keys [vi | emacs] Use vi or emacs-style key bindings in copy mode. The default is emacs, unless VISUAL or EDITOR contains 'vi'." – Dennis Williamson Apr 05 '17 at 16:30
  • @DennisWilliamson thank you! Makes sense, $echo $EDITOR #=> vim what did you search for in the man page? For example, :/foobar – mbigras Apr 05 '17 at 16:32
  • @mbigras I searched for "mode-keys" and looked around. – Dennis Williamson Apr 05 '17 at 16:55
  • 1
    To escape, type in Q or Ctrl + J. – Mateen Ulhaq May 02 '17 at 17:35
  • 1
    CTRL-B and then PgUp is working fine. Then I can use PgUp, PgDn or ArrUp, ArrDn. To leave and auto scroll to the end hit Esc – Markus Zeller Nov 17 '18 at 16:44
  • I know this is sort of against the spirit but I want to use my mouse... – Charlie Parker Mar 25 '21 at 22:25
  • @CharlieParker: https://gist.github.com/paulodeleo/5594773 (I haven't tested this) – Dennis Williamson Jun 27 '22 at 12:57
  • Keyboard short cuts for more: https://tmuxcheatsheet.com/ – Convexity May 19 '23 at 07:33
  • Does anybody know how one can memorize this? – BenKoshy Jan 03 '24 at 19:46
530

Well, you should consider the proper way to set scrolling: add in your ~/.tmux.conf

set -g mouse on        #For tmux version 2.1 and up

or

set -g mode-mouse on   #For tmux versions < 2.1

It worked for me in windows and panes. Now tmux is just perfect.

Practical tmux has more info on tmux.conf files.

nonopolarity
  • 9,636
chaiyachaiya
  • 5,309
  • 1
  • 13
  • 2
  • 3
    This worked for me, but only after killing the tmux server with tmux kill-server. – Blaine Lafreniere Aug 28 '18 at 22:16
  • 6
    @pltrdy @friederbluemle @Shadoninja: with mode-mouse on use can still select text with Shift + mouse drag or Option + mouse drag on Mac. – ccpizza Apr 24 '19 at 20:27
  • Note for Windows Terminal (microsoft/terminal) users, this won't work until this issue is fixed. – Taylan Jan 02 '20 at 19:29
  • 1
    Related: https://stackoverflow.com/questions/11832199/tmux-set-g-mouse-mode-on-doesnt-work/33336609#33336609 – Gabriel Staples Mar 26 '20 at 21:00
  • 1
    tmux -V to see your tmux version. It would be nice to know how to do this within tmux too and if it was in the answer. – Charlie Parker Mar 26 '21 at 16:22
  • @ccpizza Shift+ mouse drag is not working for me on iterm – humble Jul 09 '21 at 15:23
  • @humble: on Mac use Option + drag (as mentioned in the comment) – ccpizza Jul 11 '21 at 21:44
  • Not so sure but it works after trying this for me setw -g mouse on – The Anh Nguyen Feb 05 '23 at 06:56
  • 1
    After this run tmux source-file ~/.tmux.conf to make it take effect. – aviator May 25 '23 at 21:51
  • For anyone similarly confused: it worked for me only with tmux in front: tmux set -g mode-mouse on. Only showed up to the last 1989 lines though. – Caleb Stanford Nov 11 '23 at 21:54