This is a continuation of my previous questions. I currently have the following in ~/.zsh.d/functions.sh

function zle-line-init zle-keymap-select {
    psvar[1]="${${KEYMAP/vicmd/}/(main|viins)/-- INSERT --}"
    zle reset-prompt
precmd() {
    [[ -n $vcs_info_msg_0_ ]] && psvar[2]="$vcs_info_msg_0_"

and relevant sections from my ~/.zshrc

if [ -d ~/.zsh.d ]; then
    for i in ~/.zsh.d/*; do
        if [ -r $i ]; then
            source $i
    unset i

zle -N zle-line-init
zle -N zle-keymap-select
autoload -Uz colors && colors
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats '[%b]'
zstyle ':vcs_info:*' branchformats '[%b|%r]'
zstyle ':vcs_info:*' actionformats '[%b|%a]'

# 063 is a blue

# vimode implentation
psvar[1]='-- INSERT --'
local down=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]
local mode="%F{063}%1 %(1v.%1v.)%f"
local up=$terminfo[rc]
local vimode=$down$mode$up

# current working directory as blue
local cwd='%F{063}%1~%f'

# display git branch if git repo
local git='%(2v.%F{099}%2v%f.)'

# if root then red # else blue %
local prompt_char='%(!.%F{red}%#%f.%F{063}%#%f)'

PS1=$'%{$vimode%} $cwd $git $prompt_char '
preexec () { print -rn -- $terminfo[el]; }

This works right, except that it doesn't display -- INSERT -- when the shell is first started, after that it works as expected.

Other improvement suggestions welcome.

Update I decided to work around the issue, though I still don't know why it works. For now I've set psvar[1] to -- INSERT -- out of the box, since I know it will be insert on start. This doesn't feel like a proper resolution though.

1 Answer 1


In my hacker it appears I fixed it by setting

psvar[1]='-- INSERT --'

before doing anything else with my vimode... I"m not sure I'm 100% satisfied with my solution, but it functions.

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.