if the last isearch direction is available, the following script, based on the one from Bart Schaefer, should work in both forward and backward isearch: zle-isearch-exit() { if [[ $ISEARCHDIR -eq 1 ]]; then local match mbegin mend setopt extendedglob [[ -n $LASTSEARCH ]] || return 0 : ${LBUFFER%(#b)(*)$LASTSEARCH} CURSOR=$mend[1] fi return 0 } zle -N zle-isearch-exit On Sun, Sep 25, 2011 at 12:06 PM, Madsen Zhang wrote: > Fantastic solution:). > > Bart, thank you very much!! > > > > On Sun, Sep 25, 2011 at 2:17 AM, Bart Schaefer wrote: > >> On Sep 24, 2:26pm, md 1983 wrote: >> } >> } I want to upon exiting isearch mode always place the cursor in ZLE at >> } the position as specified by the variable "isearch_start" in zsh's >> } source code, no matter it's a forward or backward search. >> >> You should be able to use the special zle-isearch-exit widget and the >> $LASTSEARCH variable to find the point in the buffer that was matched >> by the search. Here's a crude effort: >> >> zle-isearch-exit() { >> local match mbegin mend >> setopt extendedglob >> [[ -n $LASTSEARCH ]] || return 0 >> : ${BUFFER#(#b)(*)$LASTSEARCH} >> CURSOR=$mend[1] >> return 0 >> } >> zle -N zle-isearch-exit >> >> I agree that it would be nice to pass the search region at least to >> zle-isearch-exit and zle-isearch-update if not to make them generally >> available. >> > >