3

I am a rookie at using Terminal, and I am acquainting myself with it by simultaneously learning Git on it. Still new to the shortcuts therein, I accidentally pressed Cmd+K, and the whole screen went blank, giving me a little heart-attack when I couldn't "scroll up".

However, checking the git status and running ls revealed that nothing had really been "undone".

I couldn't find any info on the web for this command, which is different than Ctrl+L, the clear command.

Questions:

  1. What is actually happening when I press Cmd+K?
  2. Having cleared the screen using Cmd+K, is there any way we can resurrect the commands back on the screen?
5
  • 1
    Is it Cmd-K or Cmd-L? Did you check the menus in Terminal for any shortcuts shown there?
    – nohillside
    Commented May 13, 2023 at 12:52
  • @nohillside I did not check the shortcuts, but I just re-verified that the Cmd + K does give what I write in the op. (I am not able to find any "keyboard shortcuts" in the menus of the Terminal.)
    – Atom
    Commented May 13, 2023 at 12:58
  • @Atom why does the first part of the question say Cmd-L ?
    – mmmmmm
    Commented May 13, 2023 at 13:22
  • @mmmmmm Oh, I did mess it up. Sorry, fixed!
    – Atom
    Commented May 13, 2023 at 13:25
  • Aye, command + k plays hell when you mistakenly enter it while working in your editor :P
    – Seamus
    Commented Dec 13, 2023 at 7:19

1 Answer 1

13

Look at all the menus in an application to see the shortcuts.

For Terminal.app look in the Edit menu.

K Says clear to start. This clears all the text of the buffer just leaving the current prompt and command you are typing. In my quick test it seems to do the same as ^L

The shortcuts are all given in an Apple Support Guide https://support.apple.com/en-gb/guide/terminal/trmlshtcts/mac

I suspect the confusion that is because Apple menu says Clear to Start to differentiate it to the other clear commands e.g. clear to bookmark. As backing for that view iTerm does just call it clear and uses L based shortcuts for dealing with clear to mark.

As to getting the command back - well they have not been undone so the effects are there. Getting them back depends on your shell and its setup. The default zsh (and bash) setup will show the last commands when you press up arrow, you won't get the results that used to be shown back. There are shells that can store the results as well as the commands, xonsh for example. There are also terminal emulators that can show the command you have entered, e.g. iTerm

You must log in to answer this question.

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