Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just started using zsh and I'm configuring a few things. I've chosen the vi bindings as I'm more familiar with those. As many people before me, I soon found it would be useful to have some visual clue of the vi mode I'm in before I start typing.

Looking around various places I found a few that insert some text or other in the prompt. I've tried to adapt one of them to use a different color for my prompt, instead of adding text. Here is the relevant code:


function zle-line-init zle-keymap-select {
    zle reset-prompt

zle -N zle-line-init zle-keymap-select

PROMPT='%{${VIMODE}%}%#%{$reset_color%} '

This would get a color directive inside the ${VIMODE} variable, red if it's on insert, green if it's on cmd. It works, and updates the color correctly, so far, for all the mode changes I've used (capital C or A, i, a).

But after running a command, the prompt becomes white until I start typing something (then it becomes red). Clearing the screen through ^L makes it redraw correctly.

Can anyone please check it and tell me where I'm doing things wrong? I'm pretty sure there's also a better way of conditionally changing the color than passing it through a variable.

Thanks in advance!


Well, something really weird is happening and I don't understand it. I had to reboot my computer and when I opened a terminal the prompt stopped swapping colors between mode changes.

I took out the zle-line-init widget and source'd the .zshrc and, magically, not only does it work again, the original problem (white prompt after a command) is also gone.

So this is the current state of affairs, and I'm not sure if this'll happen again or not.


function zle-keymap-select {
    zle reset-prompt

zle -N zle-keymap-select

Does anybody know what could've been the factors involved in this?

I originally did not restart the terminal, just sourced the .zshrc to load everything up. Could something have side effects because of this?


share|improve this question

You must log in to answer this question.

Browse other questions tagged .