vi-mode.plugin.zsh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Updates editor information when the keymap changes.
  2. function zle-keymap-select() {
  3. zle reset-prompt
  4. zle -R
  5. }
  6. # Ensure that the prompt is redrawn when the terminal size changes.
  7. TRAPWINCH() {
  8. zle && { zle reset-prompt; zle -R }
  9. }
  10. zle -N zle-keymap-select
  11. zle -N edit-command-line
  12. bindkey -v
  13. # allow v to edit the command line (standard behaviour)
  14. autoload -Uz edit-command-line
  15. bindkey -M vicmd 'v' edit-command-line
  16. # allow ctrl-p, ctrl-n for navigate history (standard behaviour)
  17. bindkey '^P' up-history
  18. bindkey '^N' down-history
  19. # allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour)
  20. bindkey '^?' backward-delete-char
  21. bindkey '^h' backward-delete-char
  22. bindkey '^w' backward-kill-word
  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