Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Buffer stack in Vi mode



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@xxxxxxxxxxxxxxxx>
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".
>


Messages sorted by: Reverse Date, Date, Thread, Author