feat(zsh): add some keybinds

This commit is contained in:
2026-01-11 17:51:11 +01:00
parent 0795bba5c4
commit 3ba48caee4
2 changed files with 59 additions and 2 deletions
+59
View File
@@ -33,6 +33,65 @@ setopt INC_APPEND_HISTORY_TIME
# Emacs mode
bindkey -e
############
# Keybinds #
############
# History search keybindings
bindkey '^P' history-beginning-search-backward
bindkey '^N' history-beginning-search-forward
if ! infocmp "$TERM" >/dev/null; then
echo "TERM $TERM not supported on your system!" >&2
echo "Some keybindings might not work properly." >&2
fi
if [[ -n $terminfo ]]; then
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
typeset -g -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]}
key[CtrlLeft]=${terminfo[kLFT5]}
key[CtrlRight]=${terminfo[kRIT5]}
# Function mapping
[[ -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]}" history-beginning-search-backward
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" history-beginning-search-forward
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-history
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-history
[[ -n "${key[CtrlLeft]}" ]] && bindkey "${key[CtrlLeft]}" backward-word
[[ -n "${key[CtrlRight]}" ]] && bindkey "${key[CtrlRight]}" forward-word
bindkey "^R" history-incremental-search-backward
# Enable terminal application mode during zle editing.
# This ensures special keys (arrows, Home, End, etc.) send escape sequences
# that match the terminfo database, making our keybindings work correctly.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
autoload -Uz add-zle-hook-widget
function zle_application_mode_start { echoti smkx; }
function zle_application_mode_stop { echoti rmkx; }
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
fi
fi
###################
# Shell Variables #
###################