zsh-workers
 help / color / mirror / code / Atom feed
* vi-history-search(forward|backward) vicmd mappings
@ 2016-01-23 23:30 Larry Hynes
  2016-01-24  0:00 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Larry Hynes @ 2016-01-23 23:30 UTC (permalink / raw)
  To: zsh-workers

Hullo

The default vicmd mappings for

    vi-history-search-forward (?)

and

    vi-history-search-backward (/)

have confused me.

vi(m)-like behaviour is always to have '/' search forward and
'?' search backward.

Say my, notional, .zhistory file contains:

    foo
    bar
    baz
    qux

The search appears to begin at the last line 'qux' - as if the
history file is read in as 'vi +G .zhistory' - so to search
backwards for 'foo', I would - in vi - enter '<ESC>?' and, once
there, enter '/' to search forwards for 'baz' but it seems to be
the opposite in zsh.

In fact, if one enters '<ESC>?' on a zsh command line with
'bindkey -e' in effect the mini-buffer prompt becomes '/' to
signify a forward search, and '<ESC>/' produces a '?' to signify
a backward search, so I propose that the default mappings are,
perhaps, backwards?

Or am I missing something?


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

* Re: vi-history-search(forward|backward) vicmd mappings
  2016-01-23 23:30 vi-history-search(forward|backward) vicmd mappings Larry Hynes
@ 2016-01-24  0:00 ` Bart Schaefer
  2016-01-24 11:30   ` Larry Hynes
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2016-01-24  0:00 UTC (permalink / raw)
  To: zsh-workers

On Jan 23, 11:30pm, Larry Hynes wrote:
}
} In fact, if one enters '<ESC>?' on a zsh command line with
} 'bindkey -e' in effect the mini-buffer prompt becomes '/' to
} signify a forward search, and '<ESC>/' produces a '?' to signify
} a backward search, so I propose that the default mappings are,
} perhaps, backwards?

This is intentional.  I've always thought it was a bit weird, but
the reasoning (from 20+ years ago) goes like this:

The vi-*search-* widgets don't include the current buffer, and even
if they did the most common place to invoke a search is at the end
of the command line, and the history only extends backwards in time;
so for all those reasons it almost never makes sense to search in
the "forward" direction.

But the "muscle memory" of most vi users is accustomed to invoking
search by whacking the slash key, not the question mark.  One way
to address this would be for the search to wrap around, but it is
far more common to want to find the most recent command than the
oldest one.

Therefore slash is bound to the most useful search direction, not
to the widget that corresponds by name to the meaning in vi(m).

But sometimes you really do need to search forward, so the "opposite"
keystroke from vi(m) is bound to the opposite search direction, to
avoid having no default foward search binding at all.


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

* Re: vi-history-search(forward|backward) vicmd mappings
  2016-01-24  0:00 ` Bart Schaefer
@ 2016-01-24 11:30   ` Larry Hynes
  2016-01-24 18:41     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Larry Hynes @ 2016-01-24 11:30 UTC (permalink / raw)
  To: zsh-workers

On 2016-01-24, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jan 23, 11:30pm, Larry Hynes wrote:
> }
> } In fact, if one enters '<ESC>?' on a zsh command line with
> } 'bindkey -e' in effect the mini-buffer prompt becomes '/' to
> } signify a forward search, and '<ESC>/' produces a '?' to signify
> } a backward search, so I propose that the default mappings are,
> } perhaps, backwards?
>
> This is intentional.  I've always thought it was a bit weird, but
> the reasoning (from 20+ years ago) goes like this:
>
> The vi-*search-* widgets don't include the current buffer, and even
> if they did the most common place to invoke a search is at the end
> of the command line, and the history only extends backwards in time;
> so for all those reasons it almost never makes sense to search in
> the "forward" direction.
>
> But the "muscle memory" of most vi users is accustomed to invoking
> search by whacking the slash key, not the question mark.  One way
> to address this would be for the search to wrap around, but it is
> far more common to want to find the most recent command than the
> oldest one.

I fail all of these tests, I'm afraid; I have a lifelong
aversion to 'we've always done it that way'; I generally invoke
history search at the beginning of a command line; and my muscle
memory uses '?' to search backwards and '/' to search forwards.
(And why wouldn't it - it's the correct approach.)

I used to use zsh-history-substring-search[1] but dropped it in
favour of having a smaller and more portable zsh configuration,
and most frequently use history search to find and repeat
often-used commands, beginning from the start of an empty
command line.

I would contend that any typical vi(m) user with more than a
casual relationship with the editor would use, by memory, '?'
and '/' to search backwards and forwards, respectively. Or, to
put it another way, so far in this thread I seem to comprise the
representative sample of most vi(m) users. ;-)

I think the crux of the matter, as you've helped me to
understand it, is related to history search 'beginning' at the
end of the history file and the (potentially thorny?) issue of
search wrapping and I understand why 'it is why it is' but - on
balance - I don't agree with the approach.

My final word, which is easily ignored or overruled, is that the
default mappings are just plain 'wrong' and should be changed to
a more 'correct' version. With all that being said, I have no
wish to upset anyone's apple cart or get into a row about it -
and I must acknowledge that my arguments contain a lot of 'I',
'my' and 'me'! - so I deal with it by simply adding:

    bindkey -M vicmd '/' vi-history-search-forward bindkey -M
    vicmd '?' vi-history-search-backward

to my configuration files.

Thanks for the clarification Bart, I was starting to think it
was all in my head!

[1] https://github.com/zsh-users/zsh-history-substring-search


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

* Re: vi-history-search(forward|backward) vicmd mappings
  2016-01-24 11:30   ` Larry Hynes
@ 2016-01-24 18:41     ` Bart Schaefer
  2016-01-29  3:30       ` Larry Hynes
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2016-01-24 18:41 UTC (permalink / raw)
  To: zsh-workers

On Jan 24, 11:30am, Larry Hynes wrote:
}
} I fail all of these tests, I'm afraid; I have a lifelong
} aversion to 'we've always done it that way'; I generally invoke
} history search at the beginning of a command line; and my muscle
} memory uses '?' to search backwards and '/' to search forwards.
} (And why wouldn't it - it's the correct approach.)

At the time, searching history at all was kind of a new thing, and
the users didn't grasp that "earlier" implied "backward."  I guess.
I have a vague recollection that originally there wasn't even a
different prompt for forward/backward (both used "/") but I may be
wrong about that.

It always seemed a little odd to me because to search using banghist
you type !?...? so why not also type ? to start search from vicmd?
I would have changed it a long time ago, but I've never been a user
of vi mode in the shell so didn't argue about it much, and then I
simply forgot about it.

Oliver has been the most active in updating the vi widget set lately.
Perhaps he has an opinion.


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

* Re: vi-history-search(forward|backward) vicmd mappings
  2016-01-24 18:41     ` Bart Schaefer
@ 2016-01-29  3:30       ` Larry Hynes
  0 siblings, 0 replies; 5+ messages in thread
From: Larry Hynes @ 2016-01-29  3:30 UTC (permalink / raw)
  To: zsh-workers

On 2016-01-24, Bart Schaefer <schaefer@brasslantern.com> wrote:
> It always seemed a little odd to me because to search using banghist
> you type !?...? so why not also type ? to start search from vicmd?
> I would have changed it a long time ago, but I've never been a user
> of vi mode in the shell so didn't argue about it much, and then I
> simply forgot about it.
>
> Oliver has been the most active in updating the vi widget set lately.
> Perhaps he has an opinion.

FWIW, I was tooling around with csh - well, tcsh (6.18.01) - on
FreeBSD running on an old PowerPC machine this evening and it
appears to do what I would expect it to do i.e. use '?' to
search backwards and '/' to search forwards in the history file
when 'bindkey -v' is in effect.

My future happiness and sanity may depend on zsh getting this
'right'. No pressure...


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

end of thread, other threads:[~2016-01-29  3:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-23 23:30 vi-history-search(forward|backward) vicmd mappings Larry Hynes
2016-01-24  0:00 ` Bart Schaefer
2016-01-24 11:30   ` Larry Hynes
2016-01-24 18:41     ` Bart Schaefer
2016-01-29  3:30       ` Larry Hynes

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