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

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?


Solution 1:

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.

Solution 2:

According to the zshzle manual page for zsh 4.3.10, no key is bound by default. You need to add bindings to the isearch map, and only a few widgets are available. For instance, you can do:

bindkey -M isearch '^R' history-incremental-search-backward
bindkey -M isearch '^S' history-incremental-search-forward