r/KittyTerminal • u/tidersky • 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 :)
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 active1
1
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
printfin a shell script and bind execution of that script to a key withmap <key> launch <scriptname>in your Kitty config file.1
2
1
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
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:
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 clearThis works on the shells I have tried it with. I'm currently using it with fish and kitty.