Skip to content

Instantly share code, notes, and snippets.

@alesandar
Created May 4, 2017 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alesandar/85abcc927c08071b0d927d1f3145c844 to your computer and use it in GitHub Desktop.
Save alesandar/85abcc927c08071b0d927d1f3145c844 to your computer and use it in GitHub Desktop.
# zle is active only if terminal is in application mode
# 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
# [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
# [Page Up] - up a line of history
if [[ "${terminfo[kpp]}" != "" ]]; then
bindkey "${terminfo[kpp]}" up-line-or-history
fi
# [Page Down] - down a line of history
if [[ "${terminfo[knp]}" != "" ]]; then
bindkey "${terminfo[knp]}" down-line-or-history
fi
# [Shift + Tab] - move through the completion menu backwards
if [[ "${terminfo[kcbt]}" != "" ]]; then
bindkey "${terminfo[kcbt]}" reverse-menu-complete
fi
# [Shift + Left Arrow] - move backward one word
if [[ "${terminfo[kLFT]}" != "" ]]; then
bindkey "${terminfo[kLFT]}" backward-word
else
bindkey '^[[1;2D' backward-word
fi
# [Shift + Right Arrow] - move forward one word
if [[ "${terminfo[kRIT]}" != "" ]]; then
bindkey "${terminfo[kRIT]}" forward-word
else
bindkey '^[[1;2C' forward-word
fi
# [Up] - up line or backward search in history
if [[ "${terminfo[kcuu1]}" != "" ]]; then
autoload -Uz up-line-or-beginning-search
zle -N up-line-or-beginning-search
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
fi
# [Down] - down line or backward search in history
if [[ "${terminfo[kcud1]}" != "" ]]; then
autoload -Uz down-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
fi
# [Delete] - delete forward
if [[ "${terminfo[kdch1]}" != "" ]]; then
bindkey "${terminfo[kdch1]}" delete-char
else
bindkey "^[[3~" delete-char
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment