aboutsummaryrefslogtreecommitdiffstats
path: root/_zsh
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-06 14:31:58 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-06 14:31:58 +0800
commitf68035808bebef832d4736f2875e4dd80428f94a (patch)
tree79553c3ce225c089f9288f577067e1580aed81a5 /_zsh
parent9fa3bcc08e58212a97ddb8ffe3c8f87f982a94fa (diff)
downloaddotfiles-f68035808bebef832d4736f2875e4dd80428f94a.tar.bz2
zsh: Add more commonly used key bindings
Credit: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/key-bindings.zsh
Diffstat (limited to '_zsh')
-rw-r--r--_zsh/60-bindkeys.zsh76
1 files changed, 76 insertions, 0 deletions
diff --git a/_zsh/60-bindkeys.zsh b/_zsh/60-bindkeys.zsh
index 80ed079..a57ab83 100644
--- a/_zsh/60-bindkeys.zsh
+++ b/_zsh/60-bindkeys.zsh
@@ -9,7 +9,83 @@
# NOTE:
# Switching mode (e.g., `bindkey -v`) will *reset* the following settings!
#
+# Credit:
+# * oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh
+# lib/key-bindings.zsh
+#
+
+# Make sure that the terminal is in application mode when zle is active,
+# since only then values from $terminfo are valid
+if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
+ function zle-line-init() {
+ echoti smkx
+ }
+ function zle-line-finish() {
+ echoti rmkx
+ }
+ zle -N zle-line-init
+ zle -N zle-line-finish
+fi
+
+# [Ctrl-r] - Search backward incrementally for a specified string.
+# The string may begin with ^ to anchor the search to the beginning of the line.
+bindkey '^r' history-incremental-search-backward
+
+# [PageUp] - Up a line of history
+if [[ "${terminfo[kpp]}" != "" ]]; then
+ bindkey "${terminfo[kpp]}" up-line-or-history
+fi
+# [PageDown] - Down a line of history
+if [[ "${terminfo[knp]}" != "" ]]; then
+ bindkey "${terminfo[knp]}" down-line-or-history
+fi
+
+# start typing + [Up-Arrow] - fuzzy find history forward
+if [[ "${terminfo[kcuu1]}" != "" ]]; then
+ autoload -U up-line-or-beginning-search
+ zle -N up-line-or-beginning-search
+ bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
+fi
+# start typing + [Down-Arrow] - fuzzy find history backward
+if [[ "${terminfo[kcud1]}" != "" ]]; then
+ autoload -U down-line-or-beginning-search
+ zle -N down-line-or-beginning-search
+ bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
+fi
+
+# [Home] - Go to beginning of line
+if [[ "${terminfo[khome]}" != "" ]]; then
+ bindkey "${terminfo[khome]}" beginning-of-line
+fi
+# [End] - Go to end of line
+if [[ "${terminfo[kend]}" != "" ]]; then
+ bindkey "${terminfo[kend]}" end-of-line
+fi
+
+# [Space] - do history expansion
+bindkey ' ' magic-space
+# [Ctrl-RightArrow] - move forward one word
+bindkey '^[[1;5C' forward-word
+# [Ctrl-LeftArrow] - move backward one word
+bindkey '^[[1;5D' backward-word
+
+# [Shift-Tab] - move through the completion menu backwards
+if [[ "${terminfo[kcbt]}" != "" ]]; then
+ bindkey "${terminfo[kcbt]}" reverse-menu-complete
+fi
+
+# [Backspace] - delete backward
+bindkey '^?' backward-delete-char
+# [Delete] - delete forward
+if [[ "${terminfo[kdch1]}" != "" ]]; then
+ bindkey "${terminfo[kdch1]}" delete-char
+else
+ bindkey "^[[3~" delete-char
+ bindkey "^[3;5~" delete-char
+ bindkey "\e[3~" delete-char
+fi
+# Emacs style line editing
bindkey "^K" kill-whole-line # ctrl-k
bindkey "^R" history-incremental-search-backward # ctrl-r
bindkey "^A" beginning-of-line # ctrl-a