zsh-users / zsh-history-substring-search

🐠 ZSH port of Fish history search (up arrow)
2.61k stars 156 forks source link

How to achieve this but only with the start of the string? #116

Closed ghost closed 3 years ago

ghost commented 3 years ago

if I type py and press up arrow I want to match python code.py but not vim code.py

In this substring search, vim code.py obviously matches because py is a substring of vim code.py

I would like a simpler, start-only matcher.

Where does that exist?

guidovansteen commented 3 years ago

"up-line-or-beginning-search" and "down-line-or-beginning-search" are probably the widgets you are looking for. You can "bindkey" them in the same way as "history-substring-search-up" and "history-substring-search-down"

ghost commented 3 years ago

@guidovansteen thanks for the pointer, helping me out even though I know it's not really related to this repository.

It seems that up-line-or-beginning-search and co. actually only match the very first word on the line, up to the first non-escaped space.

so

dotnet build
dotnet bin/Debug/netcoreapp2.2/MyProg.dll
dotnet build
dotnet bin<UP ARROW>

actually fills in dotnet build instead of dotnet bin/Debug/netcoreapp2.2/MyProg.dll.

goduck777 commented 3 years ago

You can simple remove the first star in the matching string, like this

local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"

h0adp0re commented 3 years ago

This was also requested in #95 and #112, both of which also have accompanying PRs – #96 and #115, respectively.

Any thoughts from the maintainers? Seems to be a popular request. I had the same expectation after I found this plugin as I was migrating from oh-my-zsh.

sunaku commented 3 years ago

Those PRs have been merged as of commit 4abed97b6e67eb5590b39bcd59080aa23192f25d. Please set the following configuration variable to enable this feature:

HISTORY_SUBSTRING_SEARCH_PREFIXED=1
jabuxas commented 1 month ago

@guidovansteen thanks for the pointer, helping me out even though I know it's not really related to this repository.

It seems that up-line-or-beginning-search and co. actually only match the very first word on the line, up to the first non-escaped space.

so

dotnet build
dotnet bin/Debug/netcoreapp2.2/MyProg.dll
dotnet build
dotnet bin<UP ARROW>

actually fills in dotnet build instead of dotnet bin/Debug/netcoreapp2.2/MyProg.dll.

i'm rewriting my zsh config without omz and i'm running into this. even though i've set:

bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward

history-search-backward is only matching results that have the first command the same. so, with this history

ls /etc/
ls /usr/
ls /e<UP ARROW>

it changes to ls /usr, and not the ls /etc/ i would expect.