key-bindings.zsh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Overridden keybindings to have up arrow history matching and vi-mode.
  2. #
  3. # vi-mode plugin and oh-my-zsh's key-binding library don't match well, because
  4. # of the way `bindkey -v` overrides previously made bindings.
  5. #
  6. # Unfortunately, there is no nice way to reconcile the two, so parts of both
  7. # have been extracted and placed here.
  8. # Make sure that the terminal is in application mode when zle is active, since
  9. # only then values from $terminfo are valid
  10. if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
  11. function zle-line-init() {
  12. echoti smkx
  13. }
  14. function zle-line-finish() {
  15. echoti rmkx
  16. }
  17. zle -N zle-line-init
  18. zle -N zle-line-finish
  19. fi
  20. # From vi-mode: needed to get prompt indicator to work in `cinaeco.zsh-theme`
  21. function zle-keymap-select {
  22. # The terminal must be in application mode when ZLE is active for $terminfo
  23. # values to be valid.
  24. if (( ${+terminfo[smkx]} )); then
  25. printf '%s' ${terminfo[smkx]}
  26. fi
  27. if (( ${+terminfo[rmkx]} )); then
  28. printf '%s' ${terminfo[rmkx]}
  29. fi
  30. zle reset-prompt
  31. zle -R
  32. }
  33. zle -N zle-keymap-select
  34. # Start with vim bindings
  35. bindkey -v
  36. # Key bindings for history search
  37. 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.
  38. if [[ "${terminfo[kcuu1]}" != "" ]]; then
  39. bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
  40. fi
  41. if [[ "${terminfo[kcud1]}" != "" ]]; then
  42. bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
  43. fi
  44. # <S-Tab> to tab backwards through autocomplete suggestions.
  45. bindkey '^[[Z' reverse-menu-complete
  46. # Toggle Command Line Editing with <C-x><C-e>, like bash.
  47. autoload -U edit-command-line
  48. zle -N edit-command-line
  49. bindkey '\C-x\C-e' edit-command-line