diff --git a/zsh/completion b/zsh/completion index 49a00fd..ebc409e 100644 --- a/zsh/completion +++ b/zsh/completion @@ -18,8 +18,6 @@ bindkey ' ' magic-space bindkey -M menuselect '^[[Z' reverse-menu-complete bindkey -M menuselect '^M' .accept-line # Immediately execute command line on bindkey -M menuselect '^F' vi-insert # Toggle interactive mode -bindkey '^P' history-beginning-search-backward -bindkey '^N' history-beginning-search-forward # See: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Standard-Styles # :completion::::: diff --git a/zsh/rc b/zsh/rc index 2516d00..cf32d78 100644 --- a/zsh/rc +++ b/zsh/rc @@ -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 # ###################