480

How do I increase the scrollback buffer size in tmux?

If I enter copy mode, the number of available scrollback lines is always below 2000.

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
moon.musick
  • 5,125
  • 2
  • 23
  • 23
  • 4
    I'm amazed that 2k lines is still the default. 250k is more reasonable. Any machine that can't spare a handful of MB for scrollback shouldn't be running linux let alone tmux. – Navin Jul 11 '22 at 05:36
  • 4
    @Navin My guess is that they want to avoid issues when the user starts to create *lots* of panes. 250k lines, 80 character each, is 40 Mb. Which alone is fine, but just right now I have a total of 25+ panes open on my workstation; so they would eat up almost 1.5GB! Most users would be *very* surprised if they see a terminal multiplexer eating up even hundreds of megabytes, so setting scrollback to a low default value (that is still 2x more than the default of most terminal emulators) is very reasonable. – Neinstein Jul 21 '22 at 08:19
  • @Neinstein Sure, but most dev machines have swap enabled so RSS will be only a few megs. Even if I didn’t have swap, I paid for 64GB of DDR4 and I intend to use all of it! (Servers often have swap disabled to run k8s, but they usually have 1TB of RDIMM+optane so even in that situation I wouldn’t balk at 1.5GB) – Navin Jul 24 '22 at 06:01
  • 3
    @Navin TMUX is most definitely not limited to dev machines. On the contrary, as a terminal software, it has high chances to run on very low-spec hardware, such as old laptops and Raspberry Pi-style microcomputers. These may have as small as 1GB RAM, and a TMUX eating up even a few hundred MBs would be very bad. But even on normal PCs quite a few user would raise an eyebrow *very* high if a simple terminal utility software would show up eating huge chunks of RAM. 99% of users won't have a dev machine with 64GB of memory. It really is better to leave the huge scrollback opt-in. – Neinstein Jul 24 '22 at 07:32

5 Answers5

594

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
  • 11,203
  • 7
  • 53
  • 70
Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
  • 59
    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
  • 20
    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
  • 29
    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
  • 5
    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
  • 10
    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
  • 3
    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
  • tmux need off ram log store to ease fixed constraint. – Daniil Iaitskov Aug 11 '21 at 18:02
58

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
  • 1,182
  • 11
  • 21
  • 7
    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
9

This will fix it in one liner:

echo "set -g history-limit 5000" >> ~/.tmux.conf

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 if above command will throw error. (comment taken from @C.Lee on this answer)

Hrvoje
  • 13,566
  • 7
  • 90
  • 104
Oded BD
  • 2,788
  • 27
  • 30
7

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
  • 71
  • 1
  • 3
0

As the scrollback buffer size (i.e., history-limit) can't be re-set for existing panes, the workaround that worked for me thus far is using the pipe-pane command (which is similar to screen's log command).

Quoting this Unix & Linux answer:

You can use the pipe-pane command after the tmux prefix (with the default prefix, this would be CTRL+b:pipe-pane).

Example 1

The example found here will overwrite the target file (in this case, myfile):

pipe-pane "cat >myfile"

Example 2

The example in the tmux manual will bind a key combo to toggle logging and to append to the specified file instead of overwriting it:

The -o option only opens a new pipe if no previous pipe exists, allowing a pipe to be toggled with a single key, for example:

bind-key C-p pipe-pane -o 'cat >>~/output.#I-#P'
toraritte
  • 6,300
  • 3
  • 46
  • 67