key-bindings.zsh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if [[ "${terminfo[kcuu1]}" != "" ]]; then
  27. bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
  28. fi
  29. if [[ "${terminfo[kcud1]}" != "" ]]; then
  30. bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
  31. fi
  32. if [[ "${terminfo[khome]}" != "" ]]; then
  33. bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
  34. fi
  35. if [[ "${terminfo[kend]}" != "" ]]; then
  36. bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
  37. fi
  38. bindkey ' ' magic-space # [Space] - do history expansion
  39. bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
  40. bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
  41. if [[ "${terminfo[kcbt]}" != "" ]]; then
  42. bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
  43. fi
  44. bindkey '^?' backward-delete-char # [Backspace] - delete backward
  45. if [[ "${terminfo[kdch1]}" != "" ]]; then
  46. bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
  47. else
  48. bindkey "^[[3~" delete-char
  49. bindkey "^[3;5~" delete-char
  50. bindkey "\e[3~" delete-char
  51. fi
  52. # Edit the current command line in $EDITOR
  53. autoload -U edit-command-line
  54. zle -N edit-command-line
  55. bindkey '\C-x\C-e' edit-command-line
  56. # consider emacs keybindings:
  57. #bindkey -e ## emacs key bindings
  58. #
  59. #bindkey '^[[A' up-line-or-search
  60. #bindkey '^[[B' down-line-or-search
  61. #bindkey '^[^[[C' emacs-forward-word
  62. #bindkey '^[^[[D' emacs-backward-word
  63. #
  64. #bindkey -s '^X^Z' '%-^M'
  65. #bindkey '^[e' expand-cmd-path
  66. #bindkey '^[^I' reverse-menu-complete
  67. #bindkey '^X^N' accept-and-infer-next-history
  68. #bindkey '^W' kill-region
  69. #bindkey '^I' complete-word
  70. ## Fix weird sequence that rxvt produces
  71. #bindkey -s '^[[Z' '\t'
  72. #