fix(zsh): indicate vi mode in prompt

This commit is contained in:
2025-10-22 11:54:45 +02:00
parent e2b9de241d
commit 0f72c8a7d7
2 changed files with 12 additions and 7 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
# vim: set ft=zsh: # vim: set ft=zsh:
function _set_rprompt() { function _set_rprompt() {
# shellcheck disable=SC2154
local -a _status=("${pipestatus[@]}") local -a _status=("${pipestatus[@]}")
RPROMPT="" RPROMPT=""
@@ -48,7 +49,8 @@ setopt PROMPT_SUBST
# https://zsh.sourceforge.io/Doc/Release/Parameters.html # https://zsh.sourceforge.io/Doc/Release/Parameters.html
# https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html # https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
PROMPT='%(#.%F{red}.%12F)%n@%m%f %1~ %(#.#.$) ' # shellcheck disable=SC2016
PROMPT='%(#.%F{red}.%12F)%n@%m%f %1~ ${VI_MODE_INDICATOR:-%(#.#.$)} '
PROMPT_START=$'%{\e]133;A\a%}' PROMPT_START=$'%{\e]133;A\a%}'
PROMPT_END=$'%{\e]133;B\a%}' PROMPT_END=$'%{\e]133;B\a%}'
export PROMPT=${PROMPT_START}${PROMPT}${PROMPT_END} export PROMPT=${PROMPT_START}${PROMPT}${PROMPT_END}
+9 -6
View File
@@ -44,18 +44,21 @@ bindkey -a '_' vi-first-non-blank
# shellcheck disable=SC2034 # shellcheck disable=SC2034
zle_highlight=(region:bg=#323641) zle_highlight=(region:bg=#323641)
# Change cursor shape based on vi mode # Vi mode indicator in prompt
function zle-keymap-select { function zle-keymap-select {
if [[ ${KEYMAP} == main ]]; then if [[ ${KEYMAP} == vicmd ]]; then
echo -ne '\e[5 q' # Beam cursor for insert mode VI_MODE_INDICATOR="%F{yellow}N%f"
elif [[ ${KEYMAP} == vicmd ]]; then else
echo -ne '\e[1 q' # Block cursor for command mode VI_MODE_INDICATOR=""
fi fi
zle reset-prompt
} }
zle -N zle-keymap-select zle -N zle-keymap-select
function zle-line-init { function zle-line-init {
echo -ne '\e[5 q' # Beam cursor for insert mode # shellcheck disable=SC2034
VI_MODE_INDICATOR=""
zle reset-prompt
} }
zle -N zle-line-init zle -N zle-line-init