How can I put a newline in my zsh prompt without causing terminal redraw issues?
Solution 1:
This problem is due to how ZSH reprints the promt on resize events and has also annoyed me before. The solution is to make $PROMPT
single-line and print the first line of the prompt using a precmd.
So in your example that would simply be:
precmd() { print ">" }
export PROMPT=""
or for a more sophisticated example with prompt expansion in the print statement use the -rP
parameters:
precmd() { print -rP "%~" }
export PROMPT="%# "
If you have more than one precmd registered you need to use add-zsh-hook precmd
(see man zshcontrib
).
Solution 2:
How about something like this:
NEWLINE=$'\n'
PROMPT="Line1${NEWLINE}LINE2"