This should be easy, right?

In zsh for instance, you could put this in your .zshrc:

reset_widget() tput reset
zle -N reset_widget
bindkey "^L" reset_widget

However, this resets the terminal, but requires you hit the enter key to reshow the prompt.

Changing the command to echo -ne '\n' | tput reset has no effect either.

Is there a way to reset the terminal using a keyboard shortcut, without having to hit the enter key afterwards to show the prompt?

  • This displays the prompt at the top of the screen for me following the reset under zsh -f.
    – thrig
    Commented Nov 14, 2016 at 15:05
  • @thrig - yes, but then none of my other scripts work :( Commented Nov 14, 2016 at 16:37
  • Then you'll need to figure out what it is about your prompt (perhaps also hook functions) that is screwing things up.
    – thrig
    Commented Nov 14, 2016 at 16:55

1 Answer 1


thrig isn't seeing this because the act of resetting xyr terminal is causing a WINCH signal or some such, which causes ZLE to redisplay the prompt(s).

It does on the terminal that I am currently typing at, too. The terminal reset string emitted by tput reset includes the DECCOLM control sequence. This resets the terminal, from the 100 column mode that I have put it in, back to 80 column mode. The first time around, this does cause a WINCH signal because the terminal gets resized. The second time around it changes from 80 columns to 80 columns, which doesn't cause a WINCH. So I only see thrig's behaviour once on my terminal.

You aren't seeing this because that doesn't happen with your terminal and you've omitted telling ZLE that it needs to redisplay the prompt(s) as part of the widget:

reset_widget() { tput reset; builtin zle .redisplay; }

  • Like magic! So the solution to this is really shell dependent (i.e. for bash, we'll need to find another command?) Commented Nov 16, 2016 at 23:00

You must log in to answer this question.

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