key-bindings.zsh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. bindkey -e # Use emacs key bindings
  17. bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
  18. bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
  19. 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.
  20. if [[ "${terminfo[kpp]}" != "" ]]; then
  21. bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
  22. fi
  23. if [[ "${terminfo[knp]}" != "" ]]; then
  24. bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
  25. fi
  26. # start typing + [Up-Arrow] - fuzzy find history forward
  27. if [[ "${terminfo[kcuu1]}" != "" ]]; then
  28. autoload -U up-line-or-beginning-search
  29. zle -N up-line-or-beginning-search
  30. bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
  31. fi
  32. # start typing + [Down-Arrow] - fuzzy find history backward
  33. if [[ "${terminfo[kcud1]}" != "" ]]; then
  34. autoload -U down-line-or-beginning-search
  35. zle -N down-line-or-beginning-search
  36. bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
  37. fi
  38. if [[ "${terminfo[khome]}" != "" ]]; then
  39. bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
  40. fi
  41. if [[ "${terminfo[kend]}" != "" ]]; then
  42. bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
  43. fi
  44. bindkey ' ' magic-space # [Space] - do history expansion
  45. bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
  46. bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
  47. if [[ "${terminfo[kcbt]}" != "" ]]; then
  48. bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
  49. fi
  50. bindkey '^?' backward-delete-char # [Backspace] - delete backward
  51. if [[ "${terminfo[kdch1]}" != "" ]]; then
  52. bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
  53. else
  54. bindkey "^[[3~" delete-char
  55. bindkey "^[3;5~" delete-char
  56. bindkey "\e[3~" delete-char
  57. fi
  58. # Edit the current command line in $EDITOR
  59. autoload -U edit-command-line
  60. zle -N edit-command-line
  61. bindkey '\C-x\C-e' edit-command-line
  62. # file rename magick
  63. bindkey "^[m" copy-prev-shell-word
  64. # consider emacs keybindings:
  65. #bindkey -e ## emacs key bindings
  66. #
  67. #bindkey '^[[A' up-line-or-search
  68. #bindkey '^[[B' down-line-or-search
  69. #bindkey '^[^[[C' emacs-forward-word
  70. #bindkey '^[^[[D' emacs-backward-word
  71. #
  72. #bindkey -s '^X^Z' '%-^M'
  73. #bindkey '^[e' expand-cmd-path
  74. #bindkey '^[^I' reverse-menu-complete
  75. #bindkey '^X^N' accept-and-infer-next-history
  76. #bindkey '^W' kill-region
  77. #bindkey '^I' complete-word
  78. ## Fix weird sequence that rxvt produces
  79. #bindkey -s '^[[Z' '\t'
  80. #