I recently switched to zsh (finally) and am loving it! So far one thing that I am missing is Ctrl+R to do incremental history search.
I have the history set up properly


and I used vi key bindings

bindkey -v

But Ctrl+R does not work. It removes the line above the current line, which is not the behavior it should have in vim either.

Any suggestions?

  • 1
    btw a quick work-around is to use non-incremental search: Ctrl+[ / ... – maxschlepzig Jan 27 '12 at 14:16
  • 1
    Ctrl-R is an emacs shortcut. To search backwards in vi, it's ?, though in zsh's vi mode / and ? are reversed as you generally want to search backwards. – Stéphane Chazelas Dec 15 '19 at 21:33

If I recall correctly, you need to explicitly set it, even with bindkey -v. Use something like this:

bindkey -v
bindkey '^R' history-incremental-search-backward
| improve this answer | |
  • 4
    perhaps history-incremental-pattern-search-backward is an alternative action to use in that context. – maxschlepzig Jan 27 '12 at 14:18
  • 2
    @maxschlepzig sorry what is the difference between the two? – Ali Jan 27 '12 at 15:34
  • 3
    @Ali, with the -pattern- versions you can use search-patterns (which style, i.e. globbing or regex (?) depends on other parts of your zsh-configuration) - like e.g. you can use the search-pattern fo*bar with grep to match 'fobar', 'foobar', 'fooobar' etc. – maxschlepzig Jan 27 '12 at 21:03
  • 5
    I was getting an error. Wrapping ^R in double quotes did it. bindkey "^R" history-incremental-pattern-search-backward – Ramon Tayag Sep 8 '13 at 6:26
  • 2
    bindkey -v must precede history-incremental-search-backward – Deniz Feb 21 '19 at 7:22

OMZ framework has zsh-history-substring-search plugin pre-packaged. Just enable & use.

plugins=(git history-substring-search)

| improve this answer | |

bindkey -e also works and makes zsh behave more like bash. It restores other things that you may have been using like ctrl-A (beginning of line), ctrl-K (delete everything to the right of the cursor).

| 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.