To clear a tmux pane, use clear
or Ctrl+l
for basic clearing. For a complete reset, use clear && printf '\e[3J'
or reset
. You can also create a key binding like Ctrl+b C for a thorough clear command.
clear
There are multiple ways to clear the content of a tmux pane, ranging from simple screen clearing to full terminal resets. The method you choose depends on how thoroughly you want to clear the display.
# Standard shell clear command clear # Or use keyboard shortcut Ctrl+l
This moves the current line to the top of the screen and clears everything below it. However, you can still scroll back to see previous content. This is equivalent to the clear
command in most shells.
# Clear and reset scrollback buffer clear && printf '\e[3J'
This clears both the visible content and the scrollback buffer, giving you a truly clean slate. The \e[3J
ANSI escape sequence specifically clears the scrollback buffer in most terminal emulators.
# Reset the terminal reset # Or use tput tput reset
This completely resets the terminal state, clearing the screen and fixing any display issues. It's the equivalent of turning your terminal off and on again.
You can create a key binding in your ~/.tmux.conf
to clear the current pane:
# Add binding to clear screen and scrollback with prefix+C bind C send-keys "clear && printf '\e[3J'" \; send-keys "Enter"
With this binding, pressing Ctrl+b C will send the clear command followed by Enter to the current pane.
To clear all panes in a window simultaneously, you can use synchronized panes:
# Enable synchronized panes Ctrl+b :setw synchronize-panes on # Clear all panes clear # Disable synchronized panes Ctrl+b :setw synchronize-panes off
Create a function in your shell's configuration (like ~/.bashrc
or ~/.zshrc
):
# Add to your shell configuration function clear_pane() { clear && printf '\e[3J' && tmux clear-history } alias cls="clear_pane"
Now you can simply type cls
to thoroughly clear the pane and its history.
If you frequently need to clear panes, consider these key binding alternatives for your ~/.tmux.conf
:
# Clear with Ctrl+l (without prefix) bind -n C-l send-keys C-l \; run 'sleep 0.1' \; clear-history # Clear history only, without clearing the screen bind -n C-k clear-history
If you use Vim inside tmux, the Ctrl+l
binding might conflict with Vim's redraw screen command. In that case, use a different key binding or prefix-based clear command.