Skip to content

Instantly share code, notes, and snippets.

@mentalisttraceur
Last active April 1, 2023 05:12
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 mentalisttraceur/3b084f9d4a7101700190892b6e77270a to your computer and use it in GitHub Desktop.
Save mentalisttraceur/3b084f9d4a7101700190892b6e77270a to your computer and use it in GitHub Desktop.
zsh fix standard unbound keys
bindkey '^H' backward-delete-char
bindkey '^?' backward-delete-char
for keymap in emacs viins vicmd
do
bindkey -M $keymap '^[[H' vi-beginning-of-line
bindkey -M $keymap '^[[F' vi-end-of-line
bindkey -M $keymap '^[[5~' beginning-of-buffer
bindkey -M $keymap '^[[6~' end-of-buffer
done
zle -N beginning-of-buffer
zle -N end-of-buffer
function beginning-of-buffer()
{
case $LBUFFER in *$'\n'*)
zle beginning-of-buffer-or-history
return
esac
zle beginning-of-line
}
function end-of-buffer()
{
case $RBUFFER in *$'\n'*)
zle end-of-buffer-or-history
return
esac
zle end-of-line
}
@mentalisttraceur
Copy link
Author

mentalisttraceur commented Mar 26, 2023

This adds standard behavior to some keys that zsh leaves unbound by default:

  1. Backspace actually works (different terminals send different key codes for it).
  2. Home and End jump beginning or end of current line.
  3. Page Up and Page Down jump to beginning or end of the current input (different from Home and End on multiline history items).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment