61

I'm trying to setup a multiple line PS1, for zsh, but \n doesn't was parsed by zsh,

PS1="%~\n %> "

How should I set it up?

72

Use $'\n'

For example,

PROMPT="firstline"$'\n'"secondline "

or

NEWLINE=$'\n'
PROMPT="firstline${NEWLINE}secondline "
5
  • 1
    Worked just like I needed it too.
    – Justin
    May 12 '15 at 17:09
  • 4
    using NEWLINE makes it a lot easier to edit the prompt
    – cmcginty
    Dec 12 '15 at 3:20
  • 1
    What's the difference between PS1 and PROMPT variable?
    – Didier A.
    Feb 26 '16 at 2:26
  • 1
    @DidierA. PROMPT, and PROMPT2-4 are aliases of PS1-4 respectively, except that the PROMPT aliases "[do] not exist when the shell initializes in sh or ksh emulation mode."
    – Victor
    Oct 27 '17 at 10:43
  • Awesome. That works. Thanks a lot, buddy.
    – JavaRunner
    Jun 1 '20 at 17:35
31
PS1="firstline
secondline "

or

PS1=$'Hi Joe,\nwhat now?%# '

Taken from FAQ, item 3.13

1
2

Like this (I know, looks awkward):

PS1="%~
 %> "
-1

I know this is an old question, but I was looking for this as well. If you load prompinit (autoload -Uz promptinit && promptinit) you get the option for free: $prompt_newline which is $'\n%{\r%}'.

On a Debian system you can find the source code in /usr/share/zsh/functions/Prompts/promptinit and/or https://github.com/zsh-users/zsh/blob/master/Functions/Prompts/promptinit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.