7

I have the following entries on my .inputrc for bash:

"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
"\ew": copy-region-as-kill

I just moved to zsh, and would like to keep the same keyboard bindings I have in bash. Do the lines above have an equivalent in zsh?

6

Almost everything you can do in bash has a zsh equivalent, but you have to handle the translation on a case-by-case basis.

The line editor in zsh is zle. The command to bind keys is bindkey. The line edition commands that can be bound to keys are called widgets.

# You may want to call different history search commands, e.g.
# down-line-or-history or down-line-or-search (and up-*)
bindkey '^P' history-search-backward
bindkey '^N' history-search-forward
bindkey '\e[A' history-search-backward
bindkey '\e[B' history-search-forward
# The others should work already
|improve this answer|||||
1

@Gilles answer helps you with the syntax in .zshrc To find out what codes to use for each key, there is a helpful and complete list at http://zshwiki.org/home/zle/bindkeys - for me, pressing CTRL-V then the key you I to know the code for works best (anywhere including inside nano or vim).

    bindkey "^[[5~" history-search-backward
    bindkey "^[[6~" history-search-forward
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.