vi-mode.plugin.zsh 695 B

123456789101112131415161718192021222324252627
  1. function zle-line-init zle-keymap-select {
  2. zle reset-prompt
  3. }
  4. zle -N zle-line-init
  5. zle -N zle-keymap-select
  6. #changing mode clobbers the keybinds, so store the keybinds before and execute
  7. #them after
  8. binds=`bindkey -L`
  9. bindkey -v
  10. for bind in ${(@f)binds}; do eval $bind; done
  11. unset binds
  12. # if mode indicator wasn't setup by theme, define default
  13. if [[ "$MODE_INDICATOR" == "" ]]; then
  14. MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
  15. fi
  16. function vi_mode_prompt_info() {
  17. echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
  18. }
  19. # define right prompt, if it wasn't defined by a theme
  20. if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
  21. RPS1='$(vi_mode_prompt_info)'
  22. fi