21

First of all, I am using zsh and oh-my-zsh with nearly no other customization.

In zsh, when I press up-arrow, it brings me the latest commands. And if I typed some characters before I press up-arrow, it will bring me the latest command starting with those characters. It is quite an useful feature since I issue a lot of git/vim/scp commands alternatively.

But now I am switching to a keyboard without arrow keys, and I tend to use ctrl+p instead of up-arrow for history completion. However, no matter how many characters I typed before press ctrl+p, it will always bring me the latest command (not the latest starting with those characters)

How should I configure the zsh (or oh-my-zsh) to fix this?

2 Answers 2

33
bindkey "^P" up-line-or-search
2
  • 1
    Thanks a lot! I'll file an issue to oh-my-zsh to add this into its default lib/keybinding.zsh.
    – Gordon Gao
    Apr 17, 2013 at 17:25
  • 11
    You may want to add bindkey "^N" down-line-or-search as well for consistency.
    – ejoubaud
    Dec 8, 2015 at 12:45
10
bindkey -e

This uses emacs keybindings and seems to work for me.

1
  • 3
    In your shell rc file ~/.zshrc if you set export EDITOR=vim then also key binding in shell will change to vim. In this case manually set key binding to emacs mode by bindkey -e May 3, 2017 at 5:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .