zsh-users
 help / color / mirror / code / Atom feed
* Buffer stack in Vi mode
@ 2015-07-20 14:45 Evgeny Pakhomov
  2015-07-20 17:14 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Evgeny Pakhomov @ 2015-07-20 14:45 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

HI all,

Excuse me if it's not the correct place to ask - I couldn't find any better.

I'm trying to use a custom incremental history search command (
https://github.com/dvorka/hstr). It works great with "C-r" in the normal
mode, but in the Vi mode I can't use it in the same way - I can't find any
documentation on how to use buffer stack to save already entered command in
the Vi mode.

Is there any way to use it, or at this point I just have to use "C-c" prior
to executing this custom command?

Regards,
Eugene

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Buffer stack in Vi mode
  2015-07-20 14:45 Buffer stack in Vi mode Evgeny Pakhomov
@ 2015-07-20 17:14 ` Bart Schaefer
  2015-07-21  7:58   ` Evgeny Pakhomov
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-07-20 17:14 UTC (permalink / raw)
  To: zsh-users

On Jul 20,  8:45pm, Evgeny Pakhomov wrote:
}
} Excuse me if it's not the correct place to ask - I couldn't find any better.
} 
} I'm trying to use a custom incremental history search command (
} https://github.com/dvorka/hstr). It works great with "C-r" in the normal
} mode, but in the Vi mode I can't use it in the same way - I can't find any
} documentation on how to use buffer stack to save already entered command in
} the Vi mode.

Some remarks:

This is using an external program to read the history file, which means
it's probably going to break horribly for a lot of zsh configurations.
The EXTENDED_HISTORY option will probably kill it, which means that the
INC_APPEND_HISTORY_TIME and SHARE_HISTORY options will also break it.
Also if you DO NOT set INC_APPEND_HISTORY, you'll only be able to look
at the history from before the last time a shell exited.

The recommended way to configure this for zsh:

bindkey -s "\C-r" "\eqhh\n"

is using the default binding "\eq" for the push-line widget, which means
this also probably works not-so-well at the PS2 prompt (in a multi-line
construct like a "for" loop).  But I guess no worse that it would work
for bash in the same circumstances.

I'm not going to attempt to learn what else that external program does;
there are a lot of ways to search history in zsh already.

Anyway, the direct answer to your question is that you need to bind the
push-line widget to keystrokes in the vi mode keymap and then replace
"\eq" in the bindkey above with those keystrokes.  Perhaps:

bindkey -v
bindkey "^Xq" push-line
bindkey -s "^R" "^Xqhh\n"

The other answer is that this should be written as a widget and should
not use the -s option of bindkey at all:

invoke-hh() { hh </dev/tty ; zle -I }
zle -N invoke-hh
bindkey -M emacs "^R" invoke-hh
bindkey -M viins "^R" invoke-hh

Since ^R is already bound to redisplay in vi-mode, you may want to choose
something else there.

Important note:  I didn't actually look at the configuration that hh is
adding to your startup files.  If "hh" is being created as an alias,
then the widget implementation won't work (at least, not exactly as I
wrote it) and you'll have to stick with using "bindkey -s".


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Buffer stack in Vi mode
  2015-07-20 17:14 ` Bart Schaefer
@ 2015-07-21  7:58   ` Evgeny Pakhomov
  0 siblings, 0 replies; 3+ messages in thread
From: Evgeny Pakhomov @ 2015-07-21  7:58 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 2594 bytes --]

Hi Bart,

Thanks for the answer, the widget approach works great!

Just as a remark - hh knows about zsh and different history options. There
are no problems with EXTENDED_HISTORY on my setup.

Regards,
Eugene


On Mon, Jul 20, 2015 at 11:14 PM, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Jul 20,  8:45pm, Evgeny Pakhomov wrote:
> }
> } Excuse me if it's not the correct place to ask - I couldn't find any
> better.
> }
> } I'm trying to use a custom incremental history search command (
> } https://github.com/dvorka/hstr). It works great with "C-r" in the normal
> } mode, but in the Vi mode I can't use it in the same way - I can't find
> any
> } documentation on how to use buffer stack to save already entered command
> in
> } the Vi mode.
>
> Some remarks:
>
> This is using an external program to read the history file, which means
> it's probably going to break horribly for a lot of zsh configurations.
> The EXTENDED_HISTORY option will probably kill it, which means that the
> INC_APPEND_HISTORY_TIME and SHARE_HISTORY options will also break it.
> Also if you DO NOT set INC_APPEND_HISTORY, you'll only be able to look
> at the history from before the last time a shell exited.
>
> The recommended way to configure this for zsh:
>
> bindkey -s "\C-r" "\eqhh\n"
>
> is using the default binding "\eq" for the push-line widget, which means
> this also probably works not-so-well at the PS2 prompt (in a multi-line
> construct like a "for" loop).  But I guess no worse that it would work
> for bash in the same circumstances.
>
> I'm not going to attempt to learn what else that external program does;
> there are a lot of ways to search history in zsh already.
>
> Anyway, the direct answer to your question is that you need to bind the
> push-line widget to keystrokes in the vi mode keymap and then replace
> "\eq" in the bindkey above with those keystrokes.  Perhaps:
>
> bindkey -v
> bindkey "^Xq" push-line
> bindkey -s "^R" "^Xqhh\n"
>
> The other answer is that this should be written as a widget and should
> not use the -s option of bindkey at all:
>
> invoke-hh() { hh </dev/tty ; zle -I }
> zle -N invoke-hh
> bindkey -M emacs "^R" invoke-hh
> bindkey -M viins "^R" invoke-hh
>
> Since ^R is already bound to redisplay in vi-mode, you may want to choose
> something else there.
>
> Important note:  I didn't actually look at the configuration that hh is
> adding to your startup files.  If "hh" is being created as an alias,
> then the widget implementation won't work (at least, not exactly as I
> wrote it) and you'll have to stick with using "bindkey -s".
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-21  7:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-20 14:45 Buffer stack in Vi mode Evgeny Pakhomov
2015-07-20 17:14 ` Bart Schaefer
2015-07-21  7:58   ` Evgeny Pakhomov

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).