[Fix #51] Make the vi mode indicator more flexible

This commit is contained in:
Sorin Ionescu 2012-03-21 14:34:01 -04:00
parent 854c67ada4
commit a3b92bb053
2 changed files with 16 additions and 32 deletions

View file

@ -12,8 +12,11 @@ fi
# The default styles. # The default styles.
# Indicator to notify of vi insert mode.
zstyle ':omz:prompt:vi' insert '>>>'
# Indicator to notify of vi command mode. # Indicator to notify of vi command mode.
zstyle ':omz:prompt' vicmd '<<<' zstyle ':omz:prompt:vi' command '<<<'
# Indicator to notify of generating completion. # Indicator to notify of generating completion.
zstyle ':omz:completion' indicator '...' zstyle ':omz:completion' indicator '...'
@ -61,39 +64,19 @@ keyinfo=(
'BackTab' "$terminfo[kcbt]" 'BackTab' "$terminfo[kcbt]"
) )
# Restores RPROMPT when exiting vicmd. # Displays the current vi mode.
function vi-restore-rprompt() { function zle-line-init zle-line-finish zle-keymap-select {
if (( $+RPROMPT_CACHED )); then if [[ "$KEYMAP" == 'vicmd' ]]; then
RPROMPT="$RPROMPT_CACHED" zstyle -s ':omz:prompt:vi' command 'vi_prompt_info'
unset RPROMPT_CACHED else
zle reset-prompt zstyle -s ':omz:prompt:vi' insert 'vi_prompt_info'
return 0
fi fi
return 1
}
add-zsh-trap INT vi-restore-rprompt
# Displays the current vi mode (command).
function zle-keymap-select() {
if ! vi-restore-rprompt && [[ "$KEYMAP" == 'vicmd' ]]; then
RPROMPT_CACHED="$RPROMPT"
zstyle -s ':omz:prompt' vicmd RPROMPT
zle reset-prompt zle reset-prompt
fi zle -R
}
zle -N zle-keymap-select
# Resets the prompt after exiting edit-command-line.
function zle-line-init() {
vi-restore-rprompt
} }
zle -N zle-line-init zle -N zle-line-init
# Resets the prompt after the line has been accepted.
function zle-line-finish() {
vi-restore-rprompt
}
zle -N zle-line-finish zle -N zle-line-finish
zle -N zle-keymap-select
# Expands .... to ../.. # Expands .... to ../..
function expand-dot-to-parent-directory-path() { function expand-dot-to-parent-directory-path() {

View file

@ -26,7 +26,8 @@ function prompt_sorin_setup() {
add-zsh-hook precmd prompt_sorin_precmd add-zsh-hook precmd prompt_sorin_precmd
zstyle ':omz:completion' indicator '%B%F{red}...%f%b' zstyle ':omz:completion' indicator '%B%F{red}...%f%b'
zstyle ':omz:prompt' vicmd '%F{yellow}%f%B%F{red}%f%b%F{red}%f' zstyle ':omz:prompt:vi' insert ''
zstyle ':omz:prompt:vi' command ' %F{yellow}%f%B%F{red}%f%b%F{red}%f'
zstyle ':omz:plugin:git:prompt' action ':%%B%F{yellow}%s%f%%b' zstyle ':omz:plugin:git:prompt' action ':%%B%F{yellow}%s%f%%b'
zstyle ':omz:plugin:git:prompt' added ' %%B%F{green}✚%f%%b' zstyle ':omz:plugin:git:prompt' added ' %%B%F{green}✚%f%%b'
zstyle ':omz:plugin:git:prompt' ahead ' %%B%F{yellow}⬆%f%%b' zstyle ':omz:plugin:git:prompt' ahead ' %%B%F{yellow}⬆%f%%b'
@ -43,7 +44,7 @@ function prompt_sorin_setup() {
zstyle ':omz:plugin:git:prompt' rprompt '%A%B%S%a%d%m%r%U%u' zstyle ':omz:plugin:git:prompt' rprompt '%A%B%S%a%d%m%r%U%u'
PROMPT='%F{cyan}%1~%f${(e)git_prompt_info} %(!.%B%F{red}#%f%b.%B%F{green}%f%b) ' PROMPT='%F{cyan}%1~%f${(e)git_prompt_info} %(!.%B%F{red}#%f%b.%B%F{green}%f%b) '
RPROMPT='%(?::%F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_rprompt_info}' RPROMPT='${vi_prompt_info}%(?:: %F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_rprompt_info}'
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
} }