Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Implementing search / reverse search in vi mode on input
- X-seq: zsh-workers 37681
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Implementing search / reverse search in vi mode on input
- Date: Mon, 18 Jan 2016 11:29:30 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=ZTA6uFTg1l8orQ9h+5s6nD5BVKnl0+H/cziPi0kPJdM=; b=QO9RWdedGEU22sV+l6Z00NIoRam/RQZ7DQ+IZa1yiodj3e4RLsZLkKBeaus+7nbqGE nJ+U98yFKURL8G8jDfzZ8gc/pdyegLgAsozm1dV+/auOXY9uRXHC+Uz9M29QQEAcx3Cl FVd9RFhs0xDeRMVHeTXxU/WUSeDOxdN/7NUGSycbP0fWUIz8h7PznnHhMI1AdGVez3LC drLNkItkmtnscmaab1x3yu+5Kx9OyoKvYl9BEM5YPHIVoDwMYXsM9rNU+e42laPGyMqG pCvBkKAn/veJcrmxCN9R0obvavvjyq4zH8lN/sBHXotvbULGuCOGWmw7hv9MwnqHn7hk Eftw==
- In-reply-to: <CAHGkLJj2M=s6jM3A63ZMURYqyBxCXQLOwVSXSPXO9D=B3kRKDw@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHGkLJigG0kTiuhh6gevtb81gzy3DB90GzR7wtnCh2JQgD+JiA@mail.gmail.com> <CAH+w=7YS=zrnGBj1zTKyX=tjHdm=L3hCXv6HtfAsVAVM-keGuQ@mail.gmail.com> <CAHGkLJj2M=s6jM3A63ZMURYqyBxCXQLOwVSXSPXO9D=B3kRKDw@mail.gmail.com>
On Jan 18, 6:45pm, Krzysztof wrote:
}
} The same way I can jump between words (normal mode + w, see:
} http://vim.wikia.com/wiki/Moving_around) I would like to jump to search
} phrase (normal mode + / word).
Oh, I see, you want the search to include the current input buffer, not
begin with the preceding history entry. I don't know why vi-* widgets
don't already work that way when emacs widgets do.
It might be sufficient to use one of the existing emacs builtin widgets
such as history-incremental-search-backward. For more vi-like behavior,
you can wrap those up with something like this (untested):
autoload -Uz read-from-minibuffer
vi-search-buffer-or-history() {
emulate -L zsh
local mbprompt REPLY
if [[ $WIDGET = *-backward ]]
then mbprompt='?'
else mbprompt='/'
fi
# May want to install a custom keymap here
zle read-from-minibuffer $mbprompt
if [[ $WIDGET = *-backward ]]
then
zle .incremental-history-search-backward $REPLY
else
zle .incremental-history-search-forward $REPLY
fi
# Handle $? as appropriate here:
# 0 the search succeeded
# 1 the search failed
# 2 the search term was a bad pattern
# 3 the search was aborted by send-break
}
If you want even more control you can search the buffer yourself (this
is also untested but should be a reasonable outline):
vi-search-buffer-or-history() {
emulate -L zsh
local mbprompt REPLY found
if [[ $WIDGET = *-backward ]]
then mbprompt='?'
else mbprompt='/'
fi
# May want to install a custom keymap here
zle read-from-minibuffer $mbprompt
if [[ $WIDGET = *-backward ]]
then
found=${(MS)LBUFFER%$~REPLY*}
# (m) for multibyte characters here, may not be needed
if [[ -n $found ]]
then (( CURSOR -= ${(m)#found} ))
else zle vi-history-search-backward $REPLY
fi
else
found=${(MS)RBUFFER#*$~REPLY}
# (m) for multibyte characters here, may not be needed
if [[ -n $found ]]
then (( CURSOR += ${(m)#found} ))
# Theoretically there is no "forward" from the current buffer
# else zle vi-history-search-forward $REPLY
fi
fi
}
Both of these would need handling of the LASTSEARCH parameter to allow
repeated calls, I haven't gone into that detail.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author