1

In zsh, I can search my history based on what has been typed on the command line so far with:

    bindkey "\e[A" history-search-backward
    bindkey "\e[B" history-search-forward

So if I type in:

ln -s som

and hit the up arrow, it will show me the most recent command that begins with ln -s som.

In bash, I used the ctrl-p and ctrl-n to do the same thing to make it more convenient to type:

    bindkey "\C-p" history-search-backward
    bindkey "\C-n" history-search-forward

However, when I try binding C-p and C-n to the history search in zsh, the results are based on the first word in the command. So if I type in:

ln -s som

and then hit C-p, it will show all previous results that start with ln instead of ln -s som

Anybody know how I can get C-n and C-p to behave like bash in zsh?

UPDATE: I've tried various iterations of key sequence like:

bindkey "^p" ...
bindkey "^P" ...
bindkey "^P" ... (using ^V then ^P) to generate the "^P" character
bindkey "C-p" ...
bindkey "Ctrl-p" ...

But none of these make any difference.

StevieD
  • 1,506

1 Answers1

1

OK, the widget you need to get the behavior I describe is history-beginning-search-backward

So this works now:

   bindkey '^P' history-beginning-search-backward
   bindkey '^N' history-beginning-search-forward
StevieD
  • 1,506