Mikael Magnusson wrote:
On 07/01/2008, Leslie Jensen <leslie@xxxxxxx> wrote:Hello 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? Thanks /LeslieI 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
files:
-----------------------------------------------------------
_tcsh-history-search-init () {
if [[ $HISTNO == $HISTCMD || \
$CURSOR != $#BUFFER || \
$history[$HISTNO] != ${HISTORY_SEARCH}* || \
$history[$HISTNO] != ${LBUFFER}* ]]; then
HISTORY_SEARCH="$LBUFFER"
fi
}
tcsh-history-search-forward () {
_tcsh-history-search-init
zle .history-search-forward $HISTORY_SEARCH
}
tcsh-history-search-backward () {
_tcsh-history-search-init
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
Casper