Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

more tcsh-like history-search capability



By default, zsh's history-search functions look through history for
lines whose first word starts with the first word on the command line.
I prefer to search for commands that start with the string before the
cursor.

After snarfing Bart's code to handle the literal history stuff
(zsh-workers/10996), it occurred to me that I could solve my history
search problem with zle widgets as well.  This was one of the (many)
areas of zsh that I had not explored at all.  Here are my trivial zle
widgets that implement history searching the way I want it.

I don't have a good name for these widgets... the q- here is the same
as the q in ql.org -- my favorite letter.  (Some people don't outgrow
their favorite letters. :-])

It makes me happy to be using a shell that can be customized like
this. :-)

---------------------------------------------------------------------------

q-history-search-backward()
{
    local cursor=$CURSOR
    zle .history-search-backward "$LBUFFER"
    CURSOR=$cursor
}

q-history-search-forward()
{
    local cursor=$CURSOR
    zle .history-search-forward "$LBUFFER"
    CURSOR=$cursor
}

zle -N q-history-search-backward
zle -N q-history-search-forward

bindkey "^[p" q-history-search-backward
bindkey "^[n" q-history-search-forward

---------------------------------------------------------------------------

--
E. Jay Berkenbilt (ejb@xxxxxx)  |  http://www.ql.org/q/



Messages sorted by: Reverse Date, Date, Thread, Author