vi-mode.plugin.zsh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Updates editor information when the keymap changes.
  2. function zle-keymap-select() {
  3. # update keymap variable for the prompt
  4. VI_KEYMAP=$KEYMAP
  5. zle reset-prompt
  6. zle -R
  7. }
  8. zle -N zle-keymap-select
  9. zle -N edit-command-line
  10. bindkey -v
  11. # allow v to edit the command line (standard behaviour)
  12. autoload -Uz edit-command-line
  13. bindkey -M vicmd 'v' edit-command-line
  14. # allow ctrl-p, ctrl-n for navigate history (standard behaviour)
  15. bindkey '^P' up-history
  16. bindkey '^N' down-history
  17. # allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour)
  18. bindkey '^?' backward-delete-char
  19. bindkey '^h' backward-delete-char
  20. bindkey '^w' backward-kill-word
  21. # allow ctrl-r and ctrl-s to search the history
  22. bindkey '^r' history-incremental-search-backward
  23. bindkey '^s' history-incremental-search-forward
  24. # allow ctrl-a and ctrl-e to move to beginning/end of line
  25. bindkey '^a' beginning-of-line
  26. bindkey '^e' end-of-line
  27. # if mode indicator wasn't setup by theme, define default
  28. if [[ "$MODE_INDICATOR" == "" ]]; then
  29. MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
  30. fi
  31. function vi_mode_prompt_info() {
  32. echo "${${VI_KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
  33. }
  34. # define right prompt, if it wasn't defined by a theme
  35. if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
  36. RPS1='$(vi_mode_prompt_info)'
  37. fi