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

Re: History as in tcsh

Mikael Magnusson wrote:
On 07/01/2008, Leslie Jensen <leslie@xxxxxxx> wrote:

I'm used to the tcsh and now when testing zsh the first thing that I
would like to customize is the way history works. I want to type one or
two characters and then hit the up arrow and get the commands that
starts with the two characters. At the moment I have the history in the
order it was typed. Can it be done and how?


I think
bindkey '^[[A' up-line-or-search
is what you want. Although you may have to replace the ^[[A bit with
whatever your up arrow key sends to the terminal.

This doesn't quite work as expected. At least if you're used
to the tcsh model. It only searches for the first word on the
line. So if your do this:

# echo Hello
# echo doh
# echo H<up-line-or-search>  -> displays "echo doh"

The tcsh version is much more useful, so I ended up
implementing a copy. Put this somewhere in your startup

_tcsh-history-search-init () {
    if [[ $HISTNO == $HISTCMD || \
          $CURSOR != $#BUFFER || \
          $history[$HISTNO] != ${HISTORY_SEARCH}* || \
          $history[$HISTNO] != ${LBUFFER}* ]]; then

tcsh-history-search-forward () {
    zle .history-search-forward $HISTORY_SEARCH

tcsh-history-search-backward () {
    zle .history-search-backward $HISTORY_SEARCH

zle -N tcsh-history-search-forward
zle -N tcsh-history-search-backward

Now you can bindkey it to what you like:
bindkey "^[p" tcsh-history-search-backward


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