vi-mode.plugin.zsh 927 B

1234567891011121314151617181920212223242526272829303132333435
  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]} )); then
  7. printf '%s' ${terminfo[smkx]}
  8. fi
  9. if (( ${+terminfo[rmkx]} )); then
  10. printf '%s' ${terminfo[rmkx]}
  11. fi
  12. zle reset-prompt
  13. zle -R
  14. }
  15. zle -N zle-line-init
  16. zle -N zle-line-finish
  17. zle -N zle-keymap-select
  18. bindkey -v
  19. # if mode indicator wasn't setup by theme, define default
  20. if [[ "$MODE_INDICATOR" == "" ]]; then
  21. MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
  22. fi
  23. function vi_mode_prompt_info() {
  24. echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
  25. }
  26. # define right prompt, if it wasn't defined by a theme
  27. if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
  28. RPS1='$(vi_mode_prompt_info)'
  29. fi