393

How do I increase scrollback buffer size in tmux?

If I enter copy mode, the number of available scrollback lines (visible in upper right corner) is always below 2000. I tried to find a list of all tmux commands, but I can't find anything about scrollback size. For all I see the screen command for setting that option doesn't work with tmux.

Using tmux 1.8, Ubuntu 12.04 LTS, either konsole or gnome-terminal.

Community
  • 1
  • 1
moon.musick
  • 4,256
  • 2
  • 22
  • 22

3 Answers3

499

The history limit is a pane attribute that is fixed at the time of pane creation and cannot be changed for existing panes. The value is taken from the history-limit session option (the default value is 2000).

To create a pane with a different value you will need to set the appropriate history-limit option before creating the pane.

To establish a different default, you can put a line like the following in your .tmux.conf file:

set-option -g history-limit 3000

Note: Be careful setting a very large default value, it can easily consume lots of RAM if you create many panes.

For a new pane (or the initial pane in a new window) in an existing session, you can set that session’s history-limit. You might use a command like this (from a shell):

tmux set-option history-limit 5000 \; new-window

For (the initial pane of the initial window in) a new session you will need to set the “global” history-limit before creating the session:

tmux set-option -g history-limit 5000 \; new-session

Note: If you do not re-set the history-limit value, then the new value will be also used for other panes/windows/sessions created in the future; there is currently no direct way to create a single new pane/window/session with its own specific limit without (at least temporarily) changing history-limit (though show-option (especially in 1.7 and later) can help with retrieving the current value so that you restore it later).

ntc2
  • 9,654
  • 4
  • 43
  • 63
Chris Johnsen
  • 188,658
  • 24
  • 197
  • 183
  • 36
    If a "line" really is just the characters within it, then we can assume 128 bytes is a reasonable line size in memory. If I'm willing to commit 32 MB to scroll back for a single pane (which suits me, I don't use many panes), then I could increase my history limit to roughly `2 ** (25 - 7) = 256K` or 250 thousand lines. – phs Jun 02 '17 at 18:05
  • 13
    I ended up settling on `set-option -g history-limit 50000` – phs Sep 27 '17 at 00:48
  • 3
    mine seems to only go up to around 4700.. even though a new pane. tmux 1.9 – wuxmedia Jan 06 '18 at 12:24
  • 15
    For those of you that don't know where to find .tmux.conf file, you can simply create a new file at ~/.tmux.conf, then add this single line into the file set-option -g history-limit 50000 – C.Lee Apr 03 '18 at 15:55
  • 3
    A little hickup I ran into. All tmux sessions must be closed in order for this change to take an effect. Coming from GNU screen I assumed each new screen session would source the ~/.tmux.conf but that is not the case. Only when all tmux sessions are closed and new one is opened does the change to the ~/.tmux.conf have an effect. – rudolph9 Nov 14 '18 at 05:27
  • 3
    You don't strictly need to close all tmux sessions. You can also source the conf in each open session (using prefix `:source ~/.tmux.conf`), which will make new windows/panes in that session obey the new config. – henrebotha Jul 16 '19 at 09:06
  • 2
    I don't think a line *is* just the characters within it. I currently have a tmux window with 100k lines using 160M of memory. – forresthopkinsa Nov 18 '20 at 22:54
  • 1
    @C.Lee's comment is worthy of praise, it helped me anyway. Maybe make it an answer? – jamiet Apr 30 '21 at 11:52
  • Thank you @jamiet, f4d0 has already created a explanatory answer including that info [here](https://stackoverflow.com/a/50594393/4056509) – C.Lee May 03 '21 at 02:26
43

Open tmux configuration file with the following command:

vim ~/.tmux.conf

In the configuration file add the following line:

set -g history-limit 5000

Log out and log in again, start a new tmux windows and your limit is 5000 now.

f4d0
  • 927
  • 8
  • 15
  • 4
    It's not necessary to log out and in. You simply need to either quit the tmux server entirely, or make sure you source `~/.tmux.conf` in each session (& then launch new windows in those sessions & close any old windows). – henrebotha Jul 16 '19 at 09:04
  • 1
    This doesn't work for a smaller limit like 50, but it works fine with 5000. test with `seq 1 5100` and scroll back with ^B+PgUp – rubo77 Nov 12 '20 at 08:54
  • 1
    @rubo77 that is a great point and I was not aware. I did not tested it because the question is to increase the buffer, not to decrease. Allow me to ask you, why would one want to decrease the buffer? From the top of my head I can think of optimization and memory limitations? – f4d0 Nov 13 '20 at 10:53
  • 2
    I tried this by accident, but maybe you share the session with someone and don't want the others to see the longer history, limit it to 10 – rubo77 Nov 13 '20 at 11:05
5

This builds on ntc2 and Chris Johnsen's answer. I am using this whenever I want to create a new session with a custom history-limit. I wanted a way to create sessions with limited scrollback without permanently changing my history-limit for future sessions.

tmux set-option -g history-limit 100 \; new-session -s mysessionname \; set-option -g history-limit 2000

This works whether or not there are existing sessions. After setting history-limit for the new session it resets it back to the default which for me is 2000.

I created an executable bash script that makes this a little more useful. The 1st parameter passed to the script sets the history-limit for the new session and the 2nd parameter sets its session name:

#!/bin/bash
tmux set-option -g history-limit "${1}" \; new-session -s "${2}" \; set-option -g history-limit 2000
devhen
  • 51
  • 1
  • 3