On most xterm-like terminals, the Up (and it's similar for most navigation keys) send either ␛[A or ␛OA depending on whether the terminal has been put in keypad transmit mode or not. The smkx and rmkx terminfo entries can be used to put a terminal in or out of that mode.
The kcuu1 (key cursor up by 1) terminfo entry describes the sequence sent by Up when in keypad transmit mode, that is ␛OA.
Debian and derivatives have a /etc/zsh/zshrc file that does a
function zle-line-init () { emulate -L zsh printf > /dev/tty '%s' ${terminfo[smkx]} } Which puts the terminal in that mode when zle is active, which means you can now rely on the terminfo database to know what character sequences keys transmit.
The file also defines a $key associative array based on the terminfo entries to help you map those to widgets. So on those systems, you can do:
(($+key[Up])) && bindkey $key[Up] history-beginning-search-backward For something that works on systems where the terminal is in keypad transmit mode and those that don't or don't have the $key hash, you can do:
bindkey $terminfo[kcuu1] history-beginning-search-backward bindkey ${terminfo[kcuu1]/O/[} history-beginning-search-backward See also:
- My cursor keys do not work (ncurses FAQ)
- Why can't I use the cursor keys in (whatever) shell? (xterm FAQ)