Search code examples
zshzshrc

What are the default mappings for the up and down arrows keys in zsh


I am trying to bind the default functionality of the up and down arrow keys in zsh to something else. I.e. Now when I press up, it basically shows me the previous command and when I press up again it shows me the command before that. I would like to bind this functionality to another key (say ^k and ^j). So the bind would look like:

bindkey '^k' up-line-or-history
bindkey '^j' down-line-or-history

However, I was searching around and found many possibilities: up-line, up-line-or-history etc. Which mappings are the default used by zsh for the up and down arrow keys ? I'm guessing its up-line-or-history and down-line-or-history but I can't be too sure.

Version: zsh 5.7.1 (x86_64-apple-darwin19.0)


Solution

  • up-line is unbound by default; from man zshzle

    up-line (unbound) (unbound) (unbound)

    which you can confirm by grepping for up-line in the output of bindkeys:

    % bindkey | grep up-line
    "^P" up-line-or-history
    "^[OA" up-line-or-history
    "^[[A" up-line-or-history
    

    The documentation mentions that up-line-history is bound to ^P and up-arrow:

    up-line-or-history (^P ESC-[A) (k) (ESC-[A)

    Both ^[OA and ^[[A refer to the up-arrow key; I believe the duplication depends on your terminal emulator's settings, with the sequence generated by up-arrow depending on the "mode" of the terminal.