I tried:

vared -p '"$(print \"\e[1;31test\")" something' -c tmp

Output echo "$(print \"\e[1;31test\")" something

But I want to change color of test word here. Howto achieve?

2 Answers 2


The argument to -p understands prompt expansion, so it's just:

var=; vared -p '%B%F{red}something%f: ' var
  • %B: bold (%b to stop bold)
  • %F{red}: red foreground (%K for bacKground).
  • %f: restore default foreground color.


vared -p $'\e[1;31msomething: ' var

which would be equivalent to vared -p "$(printf '\e[1;31msomething: ')" (corrected from the version in your question) would be a bad idea as it would fool zle's cursor positioning by letting it think that the prompt is 18 columns wide while in fact it's only 11 columns wide as \e[1;31m is not visible.

  • 1
    I've just learn %f and %B. :)
    – Tuyen Pham
    Sep 14, 2018 at 10:06

Can achieve this by using double quotes after -p and load colors module of zsh.

  • This is not an answer, and fit for a comment. So remove your answer and add it as a comment. Thanks.
    – rɑːdʒɑ
    Sep 14, 2018 at 9:38
  • 1
    It seems to be in the direction of an answer; Tuyen, maybe write out the corrected command, so it’s clear what worked for you?
    – Jeff Schaller
    Sep 14, 2018 at 10:34

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.