544

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.

4
  • 17
    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. Commented Jul 11, 2022 at 5:36
  • 7
    @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. Commented Jul 21, 2022 at 8:19
  • 1
    @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) Commented Jul 24, 2022 at 6:01
  • 8
    @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. Commented Jul 24, 2022 at 7:32

7 Answers 7

662

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).

Sign up to request clarification or add additional context in comments.

11 Comments

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.
I ended up settling on set-option -g history-limit 50000
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
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.
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.
|
76

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.

6 Comments

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).
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 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?
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
@henrebotha sourcing it does not help $ cat ~/.tmux.conf set -g history-limit 5000 $ source ~/.tmux.conf bash: set: -g: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
|
13

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)

3 Comments

Nothing in ~/.tmux.conf seems to work for me
Try to check if you have other conf file configured for tmux
set -g history-limit 20000 bash: set: -g: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] :(
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

Comments

2

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'

Comments

1

I'm adding this answer because it isn't generally a good idea to just create a new configuration file and put your new configuration inside it, without first checking to see if there is an existing configuration file.

  • This is a good piece of general advice across Linux, it isn't specific to tmux

The reason for this is if you create a new configuration file, it is likely that this will clobber any configuration being loaded from files elsewhere in your system.

  • First check to see if you can find any files which look relevant:
  • find / -type f -name '*tmux.conf*' 2>/dev/null
  • This runs a find command in the root directory of your filesystem to find any files with a regex matching *tmux.conf*
  • 2>/dev/null ensures any Permission denied errors are discarded to avoid cluttering the output

On my system, it doesn't look like there is any existing configuration. But I do have this:

/usr/share/doc/tmux/example_tmux.conf

If we inspect the contents we can see it has some potentially useful presets.

However, since I don't appear to have a default configuration file being loaded from somewhere else in the system, it would seem ok for me to go ahead and create ~/.tmux.conf.

To give an example of a case where this is important (at least in my experience, on most systems) consider the case of vim.

$ find / -type f -name '*vimrc*' 2>/dev/null
/usr/share/vim/vim90/gvimrc_example.vim
/usr/share/vim/vim90/vimrc_example.vim
/etc/vim/vimrc
/etc/vim/vimrc.tiny
/home/me/.vimrc

Again, on this system there isn't a huge amount of stuff returned, however we do have /etc/vim/vimrc.

To create the file /home/me/.vimrc I copied the file /etc/vim/vimrc. This avoids losing any sensible default configuration which is preconfigured there.

If you were to just create ~/.vimrc, when vim loads, it will check for this file with higher priority than checking for general system-wide configuration files such as /etc/vim/vimrc.

That means, it won't read /etc/vim/vimrc.

If you have ever created a configuration file from scratch for tumx, vim, or any other program and wondered why the behavior changed in strange ways, this might be why.

Comments

1

Plus the answers above; for the "current window buffer" you can increase buffer-limit using command:


tmux set-option buffer-limit 3000

because in document you will see:

history-limit [lines]: Set the maximum number of lines held in window history. This setting applies only to new windows - existing window histories are not resized and retain the limit at the point they were created.

buffer-limit [number]: Set the number of buffers; as new buffers are added to the top of the stack, old ones are removed from the bottom if necessary to maintain this maximum length.

For me I prefer to use buffer-limit only for tmux-sessions that I really need history checkups and this helps to manage multiple jobs with limited resources and prevent unpredicted memory loss.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.