How to manage command history in tmux?

Quick Answer

To view tmux command history, press Ctrl+b : and use the up/down arrows to cycle through previously used tmux commands. For shell command history within a tmux pane, use your shell's history feature (typically Ctrl+r or up arrow). To save tmux command history, add set -g history-file ~/.tmux_history to your ~/.tmux.conf file.

# View command history
Ctrl+b :(then use up/down arrows)

# Save command history to file
echo "set -g history-file ~/.tmux_history" >> ~/.tmux.conf

Detailed Explanation

tmux provides several types of history functionality that are useful for different purposes. Understanding these different history mechanisms can greatly improve your productivity.

Types of History in tmux

There are three main types of history in tmux:

  • Command history - Previous tmux commands entered in the command prompt
  • Scrollback history - Terminal output saved in each pane's buffer
  • Shell history - Command history of the shell running in each pane (bash, zsh, etc.)

tmux Command History

tmux maintains a history of commands entered in the command prompt (accessed with Ctrl+b :):

  1. Press Ctrl+b : to access the command prompt
  2. Use the up/down arrow keys to cycle through previously used commands
  3. Press Enter to execute a command
  4. Press Escape to cancel

Saving tmux Command History

By default, tmux's command history is not saved between sessions. To enable persistent command history:

# Add to ~/.tmux.conf
set -g history-file ~/.tmux_history

This configuration saves the command history to the specified file, making it available across tmux sessions and server restarts.

Accessing Scrollback History

tmux keeps a record of terminal output for each pane, which you can access in copy mode:

  1. Press Ctrl+b [ to enter copy mode
  2. Use the arrow keys or Vim/Emacs navigation keys to scroll through the history
  3. Press q to exit copy mode

The default scrollback size is 2000 lines. To increase it:

# Add to ~/.tmux.conf
set -g history-limit 10000  # Increase to 10,000 lines