17

I'm using tmux with iTerm2.

Clear screen using Ctrl-L works when i'm in bash, but does not work when i'm tailing server logs. How do i fix this?

Sathish
  • 171
  • 1
  • 3

3 Answers3

17

You can clear the current buffer using send-keys -R but keep in mind that the application running inside that buffer will not notice that the buffer contents have been wiped.

Reference

jjungnickel
  • 1,264
  • 11
  • 9
  • 3
    i did this: `bind l send-keys -R; display "Cleared"` – phoet Feb 05 '14 at 18:56
  • 4
    This is the final clear screen that actually works for me like CMD-k in Terminal.app on Os X: `bind -n C-k send-keys -R \; send-keys C-l \; clear-history` – Adam Wallner Nov 21 '16 at 08:56
5

Ctrl-L is bound to a readline command. However, while you are running the command that tails your log, bash is not receiving keyboard input. You could suspend the tail with Ctrl-Z, clear the screen with Ctrl-L, and resume the tail with fg.

This is independent of tmux; I don't think tmux has anything like a clear-pane command, instead relying on the shell to handle that for you.

chepner
  • 497,756
  • 71
  • 530
  • 681
5

In OSX (Terminal and I believe iTerm2), CMD+K clears and removes scrollback but I'm not sure this works when tailing or in tmux.

A couple of links may have your answer:

Also, @chepner suggested suspending the command and this gave me the idea to add it as a key binding (note: I've tested this on Linux but I don't have OSX. The first link seems to indicate clear-history may work):

bind-key -n C-l send-keys C-z \; send-keys " reset && fg > /dev/null" \; send-keys "Enter"

Add this to your ~/.tmux.conf then you can do CTRL+l and that will send the required keys and commands to the terminal to automate it.

reset && fg is prefixed with a space to exclude it from history.

The > /dev/null stops the original tail command being displayed but this might be useful so could be removed if you want to see it after clearing.

Community
  • 1
  • 1
PhilT
  • 4,166
  • 1
  • 36
  • 26