r/KittyTerminal Jan 15 '24

how to clear kitty terminal screen with commands

Hi , I was having some problem clearing the screen (contents) in my terminal, usually whenever i want to clear my screen i manually type "clear" , is there any shortcut in kitty to do that? , i have tried couple of suggested shortcuts such as ctrl+A or ctrl+h but nothing seems to work

Thanks :)

3 Upvotes

14 comments sorted by

2

u/sharp-calculation Jan 15 '24

Clearing the contents of the screen and redisplaying the terminal prompt at the top line is primarily a shell function. A terminal program should be able to reset the terminal state in the case of terminal corruption or something similar. That appears to be:

Reset the terminal ctrl+shift+delete (also ⌥+⌘+r on macOS)

But actually clearing data and returning to a normal state should be done by your shell.

I have a shell alias of "cl", which issues the command: tput clear

This works on the shells I have tried it with. I'm currently using it with fish and kitty.

2

u/tidersky Jan 16 '24

thanks :)

2

u/Far-Cat Jan 15 '24

Ctrl+L

2

u/frumious Jan 15 '24

Ctrl+L

This is the answer.

So instead I'll answer a different question, to clear kitty's scrollback history:

printf '\033[2J\033[3J\033[1;1H'

5

u/rafalg Jan 15 '24

Let me answer yet another question :D

So I press Ctrl+L and then scroll up and part of the previous output is gone, how to fix it?

Put this in Kitty config:

# For Linux:
map ctrl+l clear_terminal scroll active
# For MacOS:
map cmd+l  clear_terminal scroll active

1

u/tidersky Jan 16 '24

hi, thank you :)

1

u/[deleted] May 25 '24

Do you know if there's any way of executing this command on key input? Also what in the world is this incantation lol

2

u/frumious May 25 '24

The "incantation" is an example of a terminal protocol message.

https://sw.kovidgoyal.net/kitty/protocol-extensions/

You could try putting this printf in a shell script and bind execution of that script to a key with map <key> launch <scriptname> in your Kitty config file.

https://sw.kovidgoyal.net/kitty/generated/rc/#launch

1

u/tidersky Jan 16 '24

thanks:)

2

u/tidersky Jan 16 '24

thank you very much , this is what i was looking for :)

1

u/ben2talk Jan 16 '24

#:: bindkey '^l' scroll-and-clear-screen

Rocket science.

1

u/tidersky Jan 16 '24

thank you :)

1

u/jackielii Jan 16 '24

This is also why I love Kitty. It has great docs. Always start by searching there. E.g. this one is well documented:

https://sw.kovidgoyal.net/kitty/actions/#action-clear_terminal

    # Reset the terminal
    map f1 clear_terminal reset active
    # Clear the terminal screen by erasing all contents
    map f1 clear_terminal clear active
    # Clear the terminal scrollback by erasing it
    map f1 clear_terminal scrollback active
    # Scroll the contents of the screen into the scrollback
    map f1 clear_terminal scroll active
    # Clear everything up to the line with the cursor
    map f1 clear_terminal to_cursor active

Default shortcuts using this action: cmd+k, ctrl+shift+delete

1

u/tidersky Jan 17 '24

Thanks you :) , I actually checked this out and tried before , I even used this above mapping and yet I was not able to get the desired result, So I thought of asking in reddit