Cycle through matches in ZSH history-incremental-pattern-search-backward

historyzsh

I recently switched the history search to use history-incremental-pattern-search-backward since it allows for patterns in the search. Here is how it is setup in my .zshrc

bindkey -M vicmd '/' history-incremental-pattern-search-backward

This works great, but I can't figure out how to go to the next match from the search menu.

% cat foobarbaz.txt
bck-i-search: f*baz

Is there a key bound to do this?

Best Answer

Finally found the right incantation. You need to map the pattern search in insert mode. This was the piece I was missing:

# Search backwards and forwards with a pattern
bindkey -M vicmd '/' history-incremental-pattern-search-backward
bindkey -M vicmd '?' history-incremental-pattern-search-forward

# set up for insert mode too
bindkey -M viins '^R' history-incremental-pattern-search-backward
bindkey -M viins '^F' history-incremental-pattern-search-forward

I would have used ^B for backwards search in insert mode, but I have that mapped to something else. So now ^R and ^F cycle through the matches.

Related Question