Diff
1diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh
2index 9a410c1fb88470c96c395497af0a1e900fde604f..d44be69d43db3342957e2a65ecea582dc4245f64 100644
3--- a/plugins/vi-mode/vi-mode.plugin.zsh
4+++ b/plugins/vi-mode/vi-mode.plugin.zsh
5@@ -43,12 +43,25 @@ function _vi-mode-set-cursor-shape-for-keymap() {
6 printf $'\e[%d q' "${_shape}"
7 }
8
9+function _vi-mode-should-reset-prompt() {
10+ # If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE is unset (default), dynamically
11+ # check whether we're using the prompt to display vi-mode info
12+ if [[ -z "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" ]]; then
13+ [[ "${PS1} ${RPS1}" = *'$(vi_mode_prompt_info)'* ]]
14+ return $?
15+ fi
16+
17+ # If $VI_MODE_RESET_PROMPT_ON_MODE_CHANGE was manually set, let's check
18+ # if it was specifically set to true or it was disabled with any other value
19+ [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE}" = true ]]
20+}
21+
22 # Updates editor information when the keymap changes.
23 function zle-keymap-select() {
24 # update keymap variable for the prompt
25 typeset -g VI_KEYMAP=$KEYMAP
26
27- if [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]]; then
28+ if _vi-mode-should-reset-prompt; then
29 zle reset-prompt
30 zle -R
31 fi
32@@ -59,10 +72,9 @@ zle -N zle-keymap-select
33 # These "echoti" statements were originally set in lib/key-bindings.zsh
34 # Not sure the best way to extend without overriding.
35 function zle-line-init() {
36- local prev_vi_keymap
37- prev_vi_keymap="${VI_KEYMAP:-}"
38+ local prev_vi_keymap="${VI_KEYMAP:-}"
39 typeset -g VI_KEYMAP=main
40- [[ "$prev_vi_keymap" != 'main' ]] && [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]] && zle reset-prompt
41+ [[ "$prev_vi_keymap" != 'main' ]] && _vi-mode-should-reset-prompt && zle reset-prompt
42 (( ! ${+terminfo[smkx]} )) || echoti smkx
43 _vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}"
44 }
45@@ -138,13 +150,6 @@ if [[ -z "$MODE_INDICATOR" ]]; then
46 fi
47
48 function vi_mode_prompt_info() {
49- # If we're using the prompt to display mode info, and we haven't explicitly
50- # disabled "reset prompt on mode change", then set it here.
51- #
52- # We do that here instead of the `if` statement below because the user may
53- # set RPS1/RPROMPT to something else in their custom config.
54- : "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:=true}"
55-
56 echo "${${VI_KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/$INSERT_MODE_INDICATOR}"
57 }
58