]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/vi-mode/vi-mode.plugin.zsh
f91be70e4c5316856b93f7a18134a3e62b66aabc
[dotfiles.git] / zsh / plugins / vi-mode / vi-mode.plugin.zsh
1 # Ensures that $terminfo values are valid and updates editor information when
2 # the keymap changes.
3 function zle-keymap-select zle-line-init zle-line-finish {
4 # The terminal must be in application mode when ZLE is active for $terminfo
5 # values to be valid.
6 if (( $+terminfo[smkx] && $+terminfo[rmkx] )); then
7 case "$0" in
8 (zle-line-init)
9 # Enable terminal application mode.
10 echoti smkx
11 ;;
12 (zle-line-finish)
13 # Disable terminal application mode.
14 echoti rmkx
15 ;;
16 esac
17 fi
18 zle reset-prompt
19 zle -R
20 }
21
22 zle -N zle-line-init
23 zle -N zle-line-finish
24 zle -N zle-keymap-select
25
26 bindkey -v
27
28 # if mode indicator wasn't setup by theme, define default
29 if [[ "$MODE_INDICATOR" == "" ]]; then
30 MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
31 fi
32
33 function vi_mode_prompt_info() {
34 echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
35 }
36
37 # define right prompt, if it wasn't defined by a theme
38 if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
39 RPS1='$(vi_mode_prompt_info)'
40 fi