0

I want a keyboard shortcut that will clear everything from the terminal window, including the current line

I know that

  • Command-K clears the text to the very beginning, but if you have some text on the current line and you haven't pressed the Return key yet, Command-K preserves it.
  • Control-U clears the current line.

Is there a keyboard shortcut to do both things in a single step, or any other way to accomplish this?

8
  • While, CMD-K is a Terminal shortcut, CTRL-U is a shell command. You could combine the two maybe in Automator but that sounds like a lot of effort to eliminate one keystroke. Is it worth it? Commented 2 days ago
  • @AndyGriffiths Combining them using Automator is indeed too much for me. I hoped there is a built-in keyboard shortcut.
    – jsx97
    Commented 2 days ago
  • Ctrl-U clears from cursor to start of line (same as Cmd-K). What kind of functionality do you want to achieve by combining both?
    – nohillside
    Commented 2 days ago
  • "Ctrl-U clears from cursor to start of line (same as Cmd-K)." - Not exactly. Type echo foo and press Return. Then type echo bar, but don't press Return, and press Command-K instead. Command-K will remove echo foo, but not echo bar. "What kind of functionality do you want to achieve by combining both? " - Not sure what you mean. The functionality is exhaustively described in the question itself, isn't it? (Or, in other words, I want a keyboard shortcut that will clear everything from the terminal window, including the current line.)
    – jsx97
    Commented 2 days ago
  • 1
    Something like calling clear then, leaving just one prompt at the top of the screen?
    – nohillside
    Commented 2 days ago

1 Answer 1

2

If you just want to achieve this in your shell(bash/zsh), there are two ways to do this. (This guide uses bash as example)

  1. you can try binding the escape sequence that clears your screen and scroll back \e[2J\e[3J to your bash key binding, so it first sends this escape sequence, then execute unix-line-discard. For how to bind one key to two actions see here.

  2. You can, in Terminal settings, set cmd+k to send a key sequence that calls clear-display and unix-line-discard by inputing \e\C-l\C-u.

(Untested yet, may contain errors)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .