Last Updated: February 25, 2016
· vpetro

ZSH reverse history search with regex.

Reverse history search is a great feature. When using ZSH is possible to specify a regex pattern instead of a list of words.

To enable this add the following line to your .zshrc.

bindkey '^R' history-incremental-pattern-search-backward

Now Ctrl-R will use regex patterns to search shell history.

If you're using vim mode. The the next two lines maybe useful as well. They enable moving up and down through the history with vim-like bindings.

bindkey "^P" vi-up-line-or-history
bindkey "^N" vi-down-line-or-history

3 Responses
Add your response


I get an error "No such widget `history-incremental-pattern-search-backward'"

over 1 year ago ·

I am running zsh 5.0.2 (x86_64-apple-darwin11.4.2)

The feature is documented here: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html

over 1 year ago ·

Just to clarify, this does not support regex, it supports patterns as described in http://zsh.sourceforge.net/Doc/Release/Expansion.html#Filename-Generation (e.g. globs).

over 1 year ago ·