key-bindings.zsh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
  2. # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
  3. # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
  4. # Make sure that the terminal is in application mode when zle is active, since
  5. # only then values from $terminfo are valid
  6. if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
  7. function zle-line-init() {
  8. echoti smkx
  9. }
  10. function zle-line-finish() {
  11. echoti rmkx
  12. }
  13. zle -N zle-line-init
  14. zle -N zle-line-finish
  15. fi
  16. # Use emacs key bindings
  17. bindkey -e
  18. # [PageUp] - Up a line of history
  19. if [[ -n "${terminfo[kpp]}" ]]; then
  20. bindkey -M emacs "${terminfo[kpp]}" up-line-or-history
  21. bindkey -M viins "${terminfo[kpp]}" up-line-or-history
  22. bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history
  23. fi
  24. # [PageDown] - Down a line of history
  25. if [[ -n "${terminfo[knp]}" ]]; then
  26. bindkey -M emacs "${terminfo[knp]}" down-line-or-history
  27. bindkey -M viins "${terminfo[knp]}" down-line-or-history
  28. bindkey -M vicmd "${terminfo[knp]}" down-line-or-history
  29. fi
  30. # Start typing + [Up-Arrow] - fuzzy find history forward
  31. autoload -U up-line-or-beginning-search
  32. zle -N up-line-or-beginning-search
  33. bindkey -M emacs "^[[A" up-line-or-beginning-search
  34. bindkey -M viins "^[[A" up-line-or-beginning-search
  35. bindkey -M vicmd "^[[A" up-line-or-beginning-search
  36. if [[ -n "${terminfo[kcuu1]}" ]]; then
  37. bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search
  38. bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search
  39. bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search
  40. fi
  41. # Start typing + [Down-Arrow] - fuzzy find history backward
  42. autoload -U down-line-or-beginning-search
  43. zle -N down-line-or-beginning-search
  44. bindkey -M emacs "^[[B" down-line-or-beginning-search
  45. bindkey -M viins "^[[B" down-line-or-beginning-search
  46. bindkey -M vicmd "^[[B" down-line-or-beginning-search
  47. if [[ -n "${terminfo[kcud1]}" ]]; then
  48. bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search
  49. bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search
  50. bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search
  51. fi
  52. # [Home] - Go to beginning of line
  53. if [[ -n "${terminfo[khome]}" ]]; then
  54. bindkey -M emacs "${terminfo[khome]}" beginning-of-line
  55. bindkey -M viins "${terminfo[khome]}" beginning-of-line
  56. bindkey -M vicmd "${terminfo[khome]}" beginning-of-line
  57. fi
  58. # [End] - Go to end of line
  59. if [[ -n "${terminfo[kend]}" ]]; then
  60. bindkey -M emacs "${terminfo[kend]}" end-of-line
  61. bindkey -M viins "${terminfo[kend]}" end-of-line
  62. bindkey -M vicmd "${terminfo[kend]}" end-of-line
  63. fi
  64. # [Shift-Tab] - move through the completion menu backwards
  65. if [[ -n "${terminfo[kcbt]}" ]]; then
  66. bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete
  67. bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete
  68. bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete
  69. fi
  70. # [Backspace] - delete backward
  71. bindkey -M emacs '^?' backward-delete-char
  72. bindkey -M viins '^?' backward-delete-char
  73. bindkey -M vicmd '^?' backward-delete-char
  74. # [Delete] - delete forward
  75. if [[ -n "${terminfo[kdch1]}" ]]; then
  76. bindkey -M emacs "${terminfo[kdch1]}" delete-char
  77. bindkey -M viins "${terminfo[kdch1]}" delete-char
  78. bindkey -M vicmd "${terminfo[kdch1]}" delete-char
  79. else
  80. bindkey -M emacs "^[[3~" delete-char
  81. bindkey -M viins "^[[3~" delete-char
  82. bindkey -M vicmd "^[[3~" delete-char
  83. bindkey -M emacs "^[3;5~" delete-char
  84. bindkey -M viins "^[3;5~" delete-char
  85. bindkey -M vicmd "^[3;5~" delete-char
  86. fi
  87. # [Ctrl-Delete] - delete whole forward-word
  88. bindkey -M emacs '^[[3;5~' kill-word
  89. bindkey -M viins '^[[3;5~' kill-word
  90. bindkey -M vicmd '^[[3;5~' kill-word
  91. # [Ctrl-RightArrow] - move forward one word
  92. bindkey -M emacs '^[[1;5C' forward-word
  93. bindkey -M viins '^[[1;5C' forward-word
  94. bindkey -M vicmd '^[[1;5C' forward-word
  95. # [Ctrl-LeftArrow] - move backward one word
  96. bindkey -M emacs '^[[1;5D' backward-word
  97. bindkey -M viins '^[[1;5D' backward-word
  98. bindkey -M vicmd '^[[1;5D' backward-word
  99. bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
  100. bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
  101. bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
  102. bindkey ' ' magic-space # [Space] - don't do history expansion
  103. # Edit the current command line in $EDITOR
  104. autoload -U edit-command-line
  105. zle -N edit-command-line
  106. bindkey '\C-x\C-e' edit-command-line
  107. # file rename magick
  108. bindkey "^[m" copy-prev-shell-word
  109. # consider emacs keybindings:
  110. #bindkey -e ## emacs key bindings
  111. #
  112. #bindkey '^[[A' up-line-or-search
  113. #bindkey '^[[B' down-line-or-search
  114. #bindkey '^[^[[C' emacs-forward-word
  115. #bindkey '^[^[[D' emacs-backward-word
  116. #
  117. #bindkey -s '^X^Z' '%-^M'
  118. #bindkey '^[e' expand-cmd-path
  119. #bindkey '^[^I' reverse-menu-complete
  120. #bindkey '^X^N' accept-and-infer-next-history
  121. #bindkey '^W' kill-region
  122. #bindkey '^I' complete-word
  123. ## Fix weird sequence that rxvt produces
  124. #bindkey -s '^[[Z' '\t'
  125. #