vi-mode.plugin.zsh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. zle -N edit-command-line
  19. bindkey -v
  20. # allow v to edit the command line (standard behaviour)
  21. autoload -Uz edit-command-line
  22. bindkey -M vicmd 'v' edit-command-line
  23. # if mode indicator wasn't setup by theme, define default
  24. if [[ "$MODE_INDICATOR" == "" ]]; then
  25. MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
  26. fi
  27. function vi_mode_prompt_info() {
  28. echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
  29. }
  30. # define right prompt, if it wasn't defined by a theme
  31. if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
  32. RPS1='$(vi_mode_prompt_info)'
  33. fi