From a51cfb43a68dcc200b2be77ca3accb3595ef57bf Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Sun, 18 Mar 2012 18:14:28 -0400 Subject: [PATCH] [Fix #46] Show vicmd indicator in all keymaps --- keyboard.zsh | 68 ++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/keyboard.zsh b/keyboard.zsh index a448b99..8bc40af 100644 --- a/keyboard.zsh +++ b/keyboard.zsh @@ -61,6 +61,40 @@ keyinfo=( 'BackTab' "$terminfo[kcbt]" ) +# Restores RPROMPT when exiting vicmd. +function vi-restore-rprompt() { + if (( $+RPROMPT_CACHED )); then + RPROMPT="$RPROMPT_CACHED" + unset RPROMPT_CACHED + zle reset-prompt + return 0 + 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 + fi +} +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 + +# Resets the prompt after the line has been accepted. +function zle-line-finish() { + vi-restore-rprompt +} +zle -N zle-line-finish + zstyle -s ':omz:editor' keymap 'keymap' if [[ "$keymap" == (emacs|) ]]; then # Use Emacs key bindings. @@ -124,40 +158,6 @@ elif [[ "$keymap" == vi ]]; then # Use vi key bindings. bindkey -v - # Restores RPROMPT when exiting vicmd. - function vi-restore-rprompt() { - if (( $+RPROMPT_CACHED )); then - RPROMPT="$RPROMPT_CACHED" - unset RPROMPT_CACHED - zle reset-prompt - return 0 - 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 - fi - } - 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 - - # Resets the prompt after the line has been accepted. - function zle-line-finish() { - vi-restore-rprompt - } - zle -N zle-line-finish - # Edit command in an external editor. bindkey -M vicmd "v" edit-command-line