vi-mode.plugin.zsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 -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. # allow ctrl-r to perform backward search in history
  24. bindkey '^r' history-incremental-search-backward
  25. # allow ctrl-a and ctrl-e to move to beginning/end of line
  26. bindkey '^a' beginning-of-line
  27. bindkey '^e' end-of-line
  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. function vi_mode_prompt_info() {
  33. echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
  34. }
  35. # define right prompt, if it wasn't defined by a theme
  36. if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
  37. RPS1='$(vi_mode_prompt_info)'
  38. fi