aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--zsh/.zshrc50
-rw-r--r--zsh/keybindings.zsh69
2 files changed, 71 insertions, 48 deletions
diff --git a/zsh/.zshrc b/zsh/.zshrc
index 79494e0..707ea61 100644
--- a/zsh/.zshrc
+++ b/zsh/.zshrc
@@ -66,56 +66,10 @@ function preexec {
PS1=$'%{${fg[blue]}%}%B%~%b%{${fg[blue]}%} %B%#%b %{${fg[default]}%}'
#PS1=$'┌─[${fg[cyan]}%B%n%b ${fg[blue]}%B%~%b$fg[default]]\n└─╼ '
-# Vi keybindings
-bindkey -v
-
-# Bind "<command mode> H" to run-help (man pages)
-bindkey -M vicmd 'H' run-help
-bindkey "^R" history-incremental-pattern-search-backward
-bindkey -M isearch '^M' accept-search # Don't run commands when retrieving from history
-
-autoload -U edit-command-line
-zle -N edit-command-line
-bindkey -M vicmd 'e' edit-command-line
-
-typeset -A key
-
-key[Home]=${terminfo[khome]}
-key[End]=${terminfo[kend]}
-key[Insert]=${terminfo[kich1]}
-key[Delete]=${terminfo[kdch1]}
-key[Up]=${terminfo[kcuu1]}
-key[Down]=${terminfo[kcud1]}
-key[Left]=${terminfo[kcub1]}
-key[Right]=${terminfo[kcuf1]}
-key[PageUp]=${terminfo[kpp]}
-key[PageDown]=${terminfo[knp]}
-
-# setup key accordingly
-[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
-[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
-[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
-[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
-[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
-[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
-[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
-[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
-[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history
-[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history
source "$ZDOTDIR"/aliases.zsh
+source "$ZDOTDIR"/keybindings.zsh
-# Finally, make sure the terminal is in application mode, when zle is
-# active. Only then are the values from $terminfo valid.
-if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
- function zle-line-init () {
- printf '%s' "${terminfo[smkx]}"
- }
- function zle-line-finish () {
- printf '%s' "${terminfo[rmkx]}"
- }
- zle -N zle-line-init
- zle -N zle-line-finish
-fi
+zle -N edit-command-line
if [[ -n "$VTE_VERSION" ]]; then
source /etc/profile.d/vte.sh
diff --git a/zsh/keybindings.zsh b/zsh/keybindings.zsh
new file mode 100644
index 0000000..cf22513
--- /dev/null
+++ b/zsh/keybindings.zsh
@@ -0,0 +1,69 @@
+##
+# Keybindings
+#
+
+bindkey -v
+
+# Shift-tab
+bindkey $terminfo[kcbt] reverse-menu-complete
+
+# Delete
+bindkey -M vicmd $terminfo[kdch1] vi-delete-char
+bindkey $terminfo[kdch1] delete-char
+
+# Insert
+bindkey -M vicmd $terminfo[kich1] vi-insert
+bindkey $terminfo[kich1] overwrite-mode
+
+# End
+bindkey -M vicmd $terminfo[kend] vi-end-of-line
+bindkey $terminfo[kend] vi-end-of-line
+
+# Backspace (and <C-h>)
+bindkey -M vicmd $terminfo[kbs] backward-char
+bindkey $terminfo[kbs] backward-delete-char
+
+# Page up (and <C-b> in vicmd)
+bindkey -M vicmd $terminfo[kpp] beginning-of-buffer-or-history
+bindkey $terminfo[kpp] beginning-of-buffer-or-history
+
+bindkey -M vicmd '^B' beginning-of-buffer-or-history
+
+# Page down (and <C-f> in vicmd)
+bindkey -M vicmd $terminfo[knp] end-of-buffer-or-history
+bindkey $terminfo[knp] end-of-buffer-or-history
+
+# Do history expansion on space
+bindkey ' ' magic-space
+#
+# Use M-w for small words
+bindkey '^[w' backward-kill-word
+bindkey '^W' vi-backward-kill-word
+
+bindkey -M vicmd '^H' backward-char
+bindkey '^H' backward-delete-char
+
+# h and l whichwrap
+bindkey -M vicmd 'h' backward-char
+bindkey -M vicmd 'l' forward-char
+
+# Incremental undo and redo
+bindkey -M vicmd '^R' redo
+bindkey -M vicmd 'u' undo
+
+# Misc
+bindkey -M vicmd 'ga' what-cursor-position
+
+# Open in editor
+bindkey -M vicmd 'v' edit-command-line
+
+# History search
+bindkey '^P' up-line-or-search
+bindkey '^N' down-line-or-search
+
+# Patterned history search with zsh expansion, globbing, etc.
+bindkey -M vicmd '^R' history-incremental-pattern-search-backward
+bindkey '^R' history-incremental-pattern-search-backward
+
+# Verify search result before accepting
+bindkey -M isearch '^M' accept-search