From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Implementing search / reverse search in vi mode on input
Date: Mon, 18 Jan 2016 11:29:30 -0800 [thread overview]
Message-ID: <160118112930.ZM6893@torch.brasslantern.com> (raw)
In-Reply-To: <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.
prev parent reply other threads:[~2016-01-18 19:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-18 8:26 Krzysztof Słonka
2016-01-18 17:29 ` Bart Schaefer
2016-01-18 17:45 ` Krzysztof Słonka
2016-01-18 19:29 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=160118112930.ZM6893@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).