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

zle history and cursor position



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