* Implementing search / reverse search in vi mode on input
@ 2016-01-18 8:26 Krzysztof Słonka
2016-01-18 17:29 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Słonka @ 2016-01-18 8:26 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 324 bytes --]
Hello everyone,
I know that by using ctrl ] + / you can search through history, but I would
like to implement searching inside command input (the same way you can
search in vim, / for forward search and ? for backward).
Can someone point me in a good direction where to start and how to
implement it in ZSH?
Best regards
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Implementing search / reverse search in vi mode on input
2016-01-18 8:26 Implementing search / reverse search in vi mode on input Krzysztof Słonka
@ 2016-01-18 17:29 ` Bart Schaefer
2016-01-18 17:45 ` Krzysztof Słonka
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-01-18 17:29 UTC (permalink / raw)
To: Krzysztof Słonka; +Cc: Zsh hackers list
On Mon, Jan 18, 2016 at 12:26 AM, Krzysztof Słonka
<krzysztofslonka@gmail.com> wrote:
>
> I know that by using ctrl ] + / you can search through history, but I would
> like to implement searching inside command input (the same way you can
> search in vim, / for forward search and ? for backward).
Could you explain in more detail what you mean by "command input"?
And exactly when do you want to search it, relative to the execution
of the command?
I suspect you believe the shell is involved in a part of the process
where it really is not, but I can't be sure.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Implementing search / reverse search in vi mode on input
2016-01-18 17:29 ` Bart Schaefer
@ 2016-01-18 17:45 ` Krzysztof Słonka
2016-01-18 19:29 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Słonka @ 2016-01-18 17:45 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 1282 bytes --]
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). Example ('_' indicates the cursor position):
ls -la /usr/local/bin/_
(When I type, ctrl + [ B , I will get)
ls -la _/usr/local/bin/
I would like to implement a feature that I can jump to the beginning of the
search phrase. Example:
ls -la /usr/local/bin/_
( ctrl + [ / ocal )
ls -la /usr/l_oacl/bin/
So basically this: http://vim.wikia.com/wiki/Searching inside vi mode of zsh
Best regards
2016-01-18 18:29 GMT+01:00 Bart Schaefer <schaefer@brasslantern.com>:
> On Mon, Jan 18, 2016 at 12:26 AM, Krzysztof Słonka
> <krzysztofslonka@gmail.com> wrote:
> >
> > I know that by using ctrl ] + / you can search through history, but I
> would
> > like to implement searching inside command input (the same way you can
> > search in vim, / for forward search and ? for backward).
>
> Could you explain in more detail what you mean by "command input"?
> And exactly when do you want to search it, relative to the execution
> of the command?
>
> I suspect you believe the shell is involved in a part of the process
> where it really is not, but I can't be sure.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Implementing search / reverse search in vi mode on input
2016-01-18 17:45 ` Krzysztof Słonka
@ 2016-01-18 19:29 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-01-18 19:29 UTC (permalink / raw)
To: Zsh hackers list
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-18 19:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-18 8:26 Implementing search / reverse search in vi mode on input 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
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).