Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zsh Line Editor History Filtering

Tags:

zsh

One of the killer features of the readline line editor is the ability to type the first few characters of a command in one's history and then up-arrow to get to it. For instance, if I have 'grep "te' in the zle buffer, the up-arrow key iterates through grep commands whose first two search characters are 't' and 'e'. In my current zsh configuration, the up arrow key does not do such filtering. Are there zle commands/widgets that would give the type of filtering I want?

like image 799
seewalker Avatar asked Nov 26 '25 12:11

seewalker


1 Answers

The widget you are looking for is history-beginning-search-backward. You can bind it to up arrow using

bindkey "^[OA" history-beginning-search-backward

or

bindkey "^[[A" history-beginning-search-backward

depending on which escape sequence your up-arrow key sends (you can just use both, to be safe).

like image 141
chepner Avatar answered Dec 01 '25 07:12

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!