How can I clear scrollback buffer in Tmux?
This same question has been plaguing me for quite some time. Here's the best I've come up with. Put this into your .tmux.conf file:
bind -n C-k clear-history
This binds ctrl-k to the tmux clear-history command. The -n after bind makes it so you don't have to issue the tmux command prefix (ctrl-b by default). I use bash, so ctrl-l already does the equivalent of typing "clear" at the command line. With these two keys I get a nice ctrl-l, ctrl-k combo, which moves all the scroll buffer off the screen (the "clear") and then deletes all that history (the tmux "clear-history" command).
It's not quite as nice as Terminal's, iTerm's, or Konsole's 1-key combos for clearing it out, but it's a world better than typing in clear-history all the time.
As @juanpaco correctly stated, clear-history
is the command to clear the scrollback buffer.
I'll add that I like to also clear what's on the screen in the same command.
Issuing a send-keys -R
resets (clears) the screen, so I use the following in my .tmux.conf
bind-key b send-keys -R \; clear-history
This clears the screen AND the scrollback buffer.
Every answer on here talks about adding new key bindings.
If you just want to do it occasionally you don't need a mapping at all...
Prefix defaults to <Ctrl-b>
Just type <prefix>
+ :
in the relevant pane and then type clear-history
and press enter.
If you are on the command line, you can run tmux clear-history
in the pane in question for the same effect.
One of the cool things about tmux is that you can just run any of the commands like that... or run them in a shell/script them like tmux command
... or make a keyboard shortcut for them.