Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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() {
    psvar[2]=()
    vcs_info
    [[ -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
        fi
    done
    unset i
fi

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 '
RPS1='%m'
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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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