How to increase scrollback buffer in tmux?

Quick Answer

To increase tmux scrollback buffer size, add set -g history-limit 10000 to your ~/.tmux.conf file (adjust the number to your desired limit). This setting controls how many lines of output each pane remembers. After adding this line, either restart tmux or reload your configuration with Ctrl+b : source-file ~/.tmux.conf.

# Add to ~/.tmux.conf
set -g history-limit 10000

# Then reload config
Ctrl+b :source-file ~/.tmux.conf

Detailed Explanation

The scrollback buffer in tmux determines how many lines of terminal output are retained in memory for each pane. Increasing this limit allows you to scroll back further in your terminal history, which is particularly useful for reviewing log outputs, command results, or long-running processes.

Understanding the Scrollback Buffer

By default, tmux sets the scrollback buffer to 2000 lines per pane. This means each pane can "remember" the last 2000 lines of output. Once this limit is reached, the oldest lines are discarded to make room for new output.

For many use cases, especially when working with verbose logs or compilers, this default limit may be too small. Increasing it allows you to retain more history and reduces the chance of losing important information.

Configuring the Scrollback Size

To permanently change the scrollback buffer size, add this line to your ~/.tmux.conf file:

# Set history limit to 10,000 lines
set -g history-limit 10000

You can choose any number based on your needs and available memory. Common values range from 5,000 to 50,000 lines. The -g flag makes this a global setting that applies to all sessions.

Applying the Configuration

After adding the line to your configuration file, you have two options to apply the change:

  1. Restart tmux: Exit all sessions and start tmux again
  2. Reload configuration: Within tmux, press Ctrl+b : and type source-file ~/.tmux.conf

Note that changing this setting only affects new panes and windows. Existing panes will keep their current history-limit setting until they are closed and reopened.

Checking Current Scrollback Size

To check the current scrollback buffer size setting:

# In tmux command mode (Ctrl+b :)
show-options -g history-limit

Temporarily Changing Scrollback Size

You can also change the scrollback size for the current tmux session only (without modifying your configuration file):

# In tmux command mode (Ctrl+b :)
set-option -g history-limit 20000

This setting will remain in effect until you restart the tmux server.

Memory Considerations

Increasing the scrollback buffer significantly will increase tmux's memory usage. Each line in the scrollback buffer consumes memory, so very large values (100,000+) can lead to high memory consumption, especially if you have many panes open.

As a rough guideline:

  • 5,000-10,000 lines: Good balance for most users
  • 20,000-30,000 lines: Better for developers working with verbose outputs
  • 50,000+ lines: For specific use cases where extensive history is required

Using Copy Mode with Scrollback

To access and navigate through your scrollback buffer:

  1. Enter copy mode by pressing Ctrl+b [
  2. Use arrow keys, Page Up/Down, or Vim/Emacs navigation keys to scroll
  3. Search the buffer with Ctrl+r (reverse search) or Ctrl+s (forward search) in Emacs mode, or / (forward) and ? (backward) in Vim mode
  4. Exit copy mode with q

Pro Tip

For exceptionally large output that exceeds even a large scrollback buffer, you can capture the pane contents to a file:

# In tmux command mode (Ctrl+b :)
capture-pane -S -
save-buffer ~/output.txt

# Or from your shell
tmux capture-pane -pS - > ~/output.txt

The -S - option tells tmux to capture from the start of the scrollback buffer.