keys.zsh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #- cursor -#
  2. zle-keymap-select() {
  3. if [ "${KEYMAP}" = vicmd ]; then
  4. printf %b '\e[4 q'
  5. elif [ "${KEYMAP}" = main ] || [ "${KEYMAP}" = viins ] \
  6. || [ -z "${KEYMAP}" ]; then
  7. printf %b '\e[5 q'
  8. fi
  9. }
  10. zle-line-init() zle -K viins; printf %b '\e[5 q'
  11. zle -N zle-keymap-select
  12. zle -N zle-line-init
  13. #- vim -#
  14. bindkey -v
  15. export KEYTIMEOUT=1
  16. __vi_bind_key() {
  17. bindkey -M viins "${1:?}" "${2:?}"
  18. bindkey -M vicmd "${1}" "${2}"
  19. }
  20. #- vim keys in tab complete menu -#
  21. bindkey -M menuselect 'h' vi-backward-char
  22. bindkey -M menuselect 'k' vi-up-line-or-history
  23. bindkey -M menuselect 'l' vi-forward-char
  24. bindkey -M menuselect 'j' vi-down-line-or-history
  25. # Include hidden files.
  26. _comp_options+=( globdots )
  27. # bindings
  28. __lfcd() {
  29. cd "$(command lf -print-last-dir "${@}" < "${TTY:-$(tty)}")"
  30. BUFFER=
  31. zle accept-line
  32. }
  33. __run_htop() { command htop < "${TTY:-$(tty)}"; zle reset-prompt; }
  34. zle -N __run_htop
  35. zle -N __lfcd
  36. __vi_bind_key '^[h' __run_htop
  37. __vi_bind_key '^o' __lfcd
  38. # Start typing + [Up-Arrow] - fuzzy find history forward
  39. autoload -U up-line-or-beginning-search
  40. zle -N up-line-or-beginning-search
  41. __vi_bind_key '^[[A' up-line-or-beginning-search
  42. # Start typing + [Down-Arrow] - fuzzy find history backward
  43. autoload -U down-line-or-beginning-search
  44. zle -N down-line-or-beginning-search
  45. __vi_bind_key '^[[B' down-line-or-beginning-search
  46. # [Shift-Tab] - move through the completion menu backwards
  47. if [ -n "${terminfo[kcbt]}" ]; then
  48. __vi_bind_key "${terminfo[kcbt]}" reverse-menu-complete
  49. fi
  50. # [Backspace] - delete backward
  51. bindkey -v '^?' backward-delete-char
  52. # [Delete] - delete forward
  53. if [[ -n "${terminfo[kdch1]}" ]]; then
  54. __vi_bind_key "${terminfo[kdch1]}" delete-char
  55. else
  56. __vi_bind_key '^[[3~' delete-char
  57. __vi_bind_key '^[3;5~' delete-char
  58. fi
  59. # [Ctrl-Delete] - delete whole forward-word
  60. __vi_bind_key '^[[3;5~' kill-word
  61. # [Ctrl-{RightArrow,f}] - move forward one word
  62. __vi_bind_key '^[[1;5C' forward-word
  63. __vi_bind_key '^[f' forward-word
  64. # [Ctrl-{LeftArrow,b}] - move backward one word
  65. __vi_bind_key '^[[1;5D' backward-word
  66. __vi_bind_key '^[b' backward-word
  67. # [Ctrl-w] - delete wprd
  68. __vi_bind_key '^[[w' kill-region
  69. # [Space] - don't do history expansion
  70. bindkey ' ' magic-space
  71. unset -f __vi_bind_key