Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zle history and cursor position
- X-seq: zsh-users 12990
- From: David Bitseff <dbitsef@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: zle history and cursor position
- Date: Sat, 28 Jun 2008 10:48:58 -0700
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
I've found this useful, so I thought I'd share. When you hit return it saves
the cursor position, and then it's restored when moving to the last command in
the history.
You need to have the cursor somewhere in the middle of the middle of the line
when hitting enter to see it work. Then press the up arrow.
### restore the cursor position when calling up/down-history ###
typeset -gi last_cursor_position=0
accept-line() {
last_cursor_position=$CURSOR
zle .accept-line
}
up-line-or-history() {
zle .up-line-or-history
if [[ $(( $HISTNO + 1 )) -ge $HISTCMD && $BUFFERLINES -eq 1 ]] ; then
CURSOR=$last_cursor_position
fi
}
down-line-or-history () {
zle .down-line-or-history
if [[ $(( $HISTNO + 1 )) -ge $HISTCMD && $BUFFERLINES -eq 1 ]] ; then
CURSOR=$last_cursor_position
fi
}
zle -N accept-line
zle -N up-line-or-history
zle -N down-line-or-history
# Local Variables:
# vim:filetype=sh
# End:
Messages sorted by:
Reverse Date,
Date,
Thread,
Author