Last Updated: November 27, 2018
· codezombie

iTerm2 + Tmux + Cmd-K

Cmd-K is known to clear the static stdout in and iTerm which doesn't work well at all with tmux. However, with the below key binding in iTerm2 you can clear the scroll back buffer per-pane.

In tmux.conf set the following binding

bind C-k send-keys -R \; clear-history

In iTerm2 preferences, in the Keys tab add a keybinding like the following.


Caveats: This will override Cmd-K in iTerm2 for all non-tmux windows as well. However, if you work in tmux often, it might just be worth it.

2 Responses
Add your response

I use this to prevent things from getting wonky when I reflexively hit cmd-k when in a program that doesn't share the its buffer with tmux:

bind k if-shell -F "#{alternate_on}" "#" "send-keys -R; clear-history; send-keys C-l"

It wraps the screen-clearing command with a check to see if you're currently in alternate screen mode, and does nothing if you are.

over 1 year ago ·

You can also set the shortcut to "Send Text: clear\n" and it will work in a single tmux pane or in a regular terminal - no need to futz with hex codes (:

over 1 year ago ·