zsh-users
 help / color / mirror / code / Atom feed
* Completion style like Vim
@ 2010-11-16 19:57 Michael Treibton
  2010-11-16 20:09 ` Benjamin R. Haskell
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Treibton @ 2010-11-16 19:57 UTC (permalink / raw)
  To: zsh-users

Hi all,

I'm wondering how i can get vim-like completion with zsh, and even if
it's possible?

For those who don't know, vim allows completion to happen on one line,
so if I have entered the following commands:

foobar hello
bar baz hello
zsh is cool
zsh is really cool

... and I were to type in:

zsh is

and then press the up or down arrow keys, I would see as completion:

zsh is cool
zsh is really cool

which would be cycled through on the single line -- that is, without
presenting the completion menu.

Is something like this possible with zsh (and I assume zle?)  Note
that I already use the following bindings:

bindkey '\e[5~' beginning-of-buffer-or-history
bindkey '\e[6~' end-of-buffer-or-history
bindkey "^[n" history-search-forward
bindkey "^[p" history-search-backward

Which don't quite do what I want.

Is this possible at all?  I hope I've explained this well enough.

Thanks!

Michael


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

* Re: Completion style like Vim
  2010-11-16 19:57 Completion style like Vim Michael Treibton
@ 2010-11-16 20:09 ` Benjamin R. Haskell
       [not found]   ` <AANLkTimqY0yVW-uHNi_pKMYRjTZJ7a1CamENMs2CpCQs@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Benjamin R. Haskell @ 2010-11-16 20:09 UTC (permalink / raw)
  To: Michael Treibton; +Cc: zsh-users

On Tue, 16 Nov 2010, Michael Treibton wrote:

> Hi all,
>
> I'm wondering how i can get vim-like completion with zsh, and even if 
> it's possible?
>
> For those who don't know, vim allows completion to happen on one line, 
> so if I have entered the following commands:
>
> foobar hello
> bar baz hello
> zsh is cool
> zsh is really cool
>
> ... and I were to type in:
>
> zsh is
>
> and then press the up or down arrow keys, I would see as completion:
>
> zsh is cool
> zsh is really cool
>
> which would be cycled through on the single line -- that is, without 
> presenting the completion menu.
>
> Is something like this possible with zsh (and I assume zle?)  Note 
> that I already use the following bindings:
>
> bindkey '\e[5~' beginning-of-buffer-or-history
> bindkey '\e[6~' end-of-buffer-or-history
> bindkey "^[n" history-search-forward
> bindkey "^[p" history-search-backward
>
> Which don't quite do what I want.
>
> Is this possible at all?  I hope I've explained this well enough.

That's not how my Vim completion works.  (Big fan of the popupmenu and 
supertab.)  I guess you like i_CTRL-X_CTRL-L?  I much prefer 
i_CTRL-X_CTRL-O for the general case, falling back to i_CTRL-X_CTRL-I. 
(Both of which I access via '<Tab>'.)

>From your description, though, I think you're looking for:

history-beginning-search-{forward,backward}

(Someone complained about the name recently, but the gist of 
'beginning-' is that it searches from the beginning of the line entered 
thus far.)

-- 
Best,
Ben


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

* Re: Completion style like Vim
       [not found]     ` <alpine.LNX.2.01.1011161606310.2792@hp>
@ 2010-11-16 21:21       ` Benjamin R. Haskell
  2010-11-17 22:43         ` Michael Treibton
  0 siblings, 1 reply; 8+ messages in thread
From: Benjamin R. Haskell @ 2010-11-16 21:21 UTC (permalink / raw)
  To: Matt Wozniski; +Cc: zsh-users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1515 bytes --]

[attempt two -- not sure if the original ever hit the current zsh-users 
address]

On Tue, 16 Nov 2010, Matt Wozniski wrote:

> On Tue, Nov 16, 2010 at 3:09 PM, Benjamin R. Haskell wrote:
> > On Tue, 16 Nov 2010, Michael Treibton wrote:
> > 
> > > Hi all,
> > > 
> > > I'm wondering how i can get vim-like completion with zsh, and even 
> > > if it's possible?
> > > 
> > > For those who don't know, vim allows completion to happen on one 
> > > line, so if I have entered the following commands:
> > > 
> > > foobar hello
> > > bar baz hello
> > > zsh is cool
> > > zsh is really cool
> > > 
> > > ... and I were to type in:
> > > 
> > > zsh is
> > > 
> > > and then press the up or down arrow keys, I would see as 
> > > completion:
> > > 
> > > zsh is cool
> > > zsh is really cool
> > 
> > That's not how my Vim completion works.  (Big fan of the popupmenu 
> > and supertab.)  I guess you like i_CTRL-X_CTRL-L?  I much prefer 
> > i_CTRL-X_CTRL-O for the general case, falling back to 
> > i_CTRL-X_CTRL-I. (Both of which I access via '<Tab>'.)
> 
> Michael was describing how it works in command-line mode, not insert 
> mode.
> 

Ah, yep.  There's the disconnect.  I do too much with Vim's 
insert-completion to think of that as "completion".

In any case, the following seems to work like Vim's command-line 
completion:

bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward

^[[A == up arrow, ^[[B == down.  Sounds like you want ^n and ^p, too.

-- 
Best,
Ben

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

* Re: Completion style like Vim
  2010-11-16 21:21       ` Benjamin R. Haskell
@ 2010-11-17 22:43         ` Michael Treibton
  2011-01-20 21:02           ` Michael Treibton
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Treibton @ 2010-11-17 22:43 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: Matt Wozniski, zsh-users

Ben --

[ Sorry about the off-list reply -- that's gmail being a pain.
Hopefully I've sorted that now. ]

On 16 November 2010 21:21, Benjamin R. Haskell <zsh@benizi.com> wrote:
> [attempt two -- not sure if the original ever hit the current zsh-users
> address]
>
> On Tue, 16 Nov 2010, Matt Wozniski wrote:
>> Michael was describing how it works in command-line mode, not insert
>> mode.

Thanks, Matt.  Apologies for not being very clear before.   I suppose
to me it was obvious what I meant by "completion" in terms of ":" mode
in VIm.  But it looks like we're all singing from the same hymn sheet
now.  :)

>
> Ah, yep.  There's the disconnect.  I do too much with Vim's
> insert-completion to think of that as "completion".
>
> In any case, the following seems to work like Vim's command-line
> completion:
>
> bindkey "^[[A" history-beginning-search-backward
> bindkey "^[[B" history-beginning-search-forward
>
> ^[[A == up arrow, ^[[B == down.  Sounds like you want ^n and ^p, too.

Thanks, Ben.  This works exactly as I want, except for one thing --
the cursor position.

Let's say I have this in my history:

get_foo
get_bar

... and assume also that I've got your bindings configured (which I do) as:

bindkey "^[[A" history-beginning-search-backward
bindkey "^[[B" history-beginning-search-forward

If I type in (at the zsh prompt):

get_

and press the up-arrow key and down-arrow key, the cursor position
remains after the underscore.  Ideally, I'd love it if the cursor,
when pressed in either up or down direction could complete the line,
*and* move to the end of the line, because now, I find myself having
to do this:

get_

press "up-arrow", and then press "End", because actually I made a typo
at the end of the line I need to correct and/or was missing some
options from the command in the first place.  With my previous
bindings for those arrow-keys, this cursor-position was not a problem.

I have no doubt zsh can do this, and I am learning about it all the
time -- and I appreciate your help and Matt's so far.  So any insights
you might have are warmly appreciated.  :)

TIA,

Michael


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

* Re: Completion style like Vim
  2010-11-17 22:43         ` Michael Treibton
@ 2011-01-20 21:02           ` Michael Treibton
  2011-01-20 22:02             ` Benjamin R. Haskell
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Treibton @ 2011-01-20 21:02 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: Matt Wozniski, zsh-users

Hi all --

On 17 November 2010 22:43, Michael Treibton <mtreibton@googlemail.com> wrote:
> Ben --
>
> [ Sorry about the off-list reply -- that's gmail being a pain.
> Hopefully I've sorted that now. ]
>
> On 16 November 2010 21:21, Benjamin R. Haskell <zsh@benizi.com> wrote:
>> [attempt two -- not sure if the original ever hit the current zsh-users
>> address]
>>
>> On Tue, 16 Nov 2010, Matt Wozniski wrote:
>>> Michael was describing how it works in command-line mode, not insert
>>> mode.
>
> Thanks, Matt.  Apologies for not being very clear before.   I suppose
> to me it was obvious what I meant by "completion" in terms of ":" mode
> in VIm.  But it looks like we're all singing from the same hymn sheet
> now.  :)
>
>>
>> Ah, yep.  There's the disconnect.  I do too much with Vim's
>> insert-completion to think of that as "completion".
>>
>> In any case, the following seems to work like Vim's command-line
>> completion:
>>
>> bindkey "^[[A" history-beginning-search-backward
>> bindkey "^[[B" history-beginning-search-forward
>>
>> ^[[A == up arrow, ^[[B == down.  Sounds like you want ^n and ^p, too.
>
> Thanks, Ben.  This works exactly as I want, except for one thing --
> the cursor position.
>
> Let's say I have this in my history:
>
> get_foo
> get_bar
>
> ... and assume also that I've got your bindings configured (which I do) as:
>
> bindkey "^[[A" history-beginning-search-backward
> bindkey "^[[B" history-beginning-search-forward
>
> If I type in (at the zsh prompt):
>
> get_
>
> and press the up-arrow key and down-arrow key, the cursor position
> remains after the underscore.  Ideally, I'd love it if the cursor,
> when pressed in either up or down direction could complete the line,
> *and* move to the end of the line, because now, I find myself having
> to do this:
>
> get_
>
> press "up-arrow", and then press "End", because actually I made a typo
> at the end of the line I need to correct and/or was missing some
> options from the command in the first place.  With my previous
> bindings for those arrow-keys, this cursor-position was not a problem.
>
> I have no doubt zsh can do this, and I am learning about it all the
> time -- and I appreciate your help and Matt's so far.  So any insights
> you might have are warmly appreciated.  :)

Was there any ideas on this, may I ask?

TIA,

Michael


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

* Re: Completion style like Vim
  2011-01-20 21:02           ` Michael Treibton
@ 2011-01-20 22:02             ` Benjamin R. Haskell
  2011-01-20 22:14               ` Michael Treibton
  0 siblings, 1 reply; 8+ messages in thread
From: Benjamin R. Haskell @ 2011-01-20 22:02 UTC (permalink / raw)
  To: Michael Treibton; +Cc: Matt Wozniski, zsh-users

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2599 bytes --]

On Thu, 20 Jan 2011, Michael Treibton wrote:

> On 17 November 2010 22:43, Michael Treibton wrote:
>> Ben --
>>
>> [ Sorry about the off-list reply -- that's gmail being a pain.
>> Hopefully I've sorted that now. ]

No problem.


>> On 16 November 2010 21:21, Benjamin R. Haskell wrote:
>>> [...]
>>>
>>> In any case, the following seems to work like Vim's command-line 
>>> completion:
>>>
>>> bindkey "^[[A" history-beginning-search-backward
>>> bindkey "^[[B" history-beginning-search-forward
>>>
>>> ^[[A == up arrow, ^[[B == down.  Sounds like you want ^n and ^p, 
>>> too.
>>
>> Thanks, Ben.  This works exactly as I want, except for one thing -- 
>> the cursor position.
>>
>> Let's say I have this in my history:
>>
>> get_foo
>> get_bar
>>
>> ... and assume also that I've got your bindings configured (which I 
>> do) as:
>>
>> bindkey "^[[A" history-beginning-search-backward
>> bindkey "^[[B" history-beginning-search-forward
>>
>> If I type in (at the zsh prompt):
>>
>> get_
>>
>> and press the up-arrow key and down-arrow key, the cursor position 
>> remains after the underscore.  Ideally, I'd love it if the cursor, 
>> when pressed in either up or down direction could complete the line, 
>> *and* move to the end of the line, because now, I find myself having 
>> to do this:
>>
>> get_
>>
>> press "up-arrow", and then press "End", because actually I made a 
>> typo at the end of the line I need to correct and/or was missing some 
>> options from the command in the first place.  With my previous 
>> bindings for those arrow-keys, this cursor-position was not a 
>> problem.
>>
>> I have no doubt zsh can do this, and I am learning about it all the 
>> time -- and I appreciate your help and Matt's so far.  So any 
>> insights you might have are warmly appreciated.  :)
>
> Was there any ideas on this, may I ask?
>

Sorry.  I never saw this for some reason...

I'm not sure there's a nice way to do this.  I think 
history-beginning-search-* uses everything preceding the cursor as the 
search.  So, if you push the cursor to EOL, your search changes, which 
might not be desirable:

e.g. history contains:

abcdef 123456
abcghi
abcdef

abc_ + the search would end up with: abcdef_ (cursor at end of line). 
Then 'abcghi' would be skipped in a successive search, even though it 
matches the original (abc), because it doesn't start with the new search 
(abcdef).

Something more clever, that would maybe:

1. reset the 'search term' on accept-line
2. on first run, keep track of the 'search term'
3. run history-beginning-search-*

_might_ do the trick.

-- 
Best,
Ben

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

* Re: Completion style like Vim
  2011-01-20 22:02             ` Benjamin R. Haskell
@ 2011-01-20 22:14               ` Michael Treibton
  2011-01-23  4:56                 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Treibton @ 2011-01-20 22:14 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: Matt Wozniski, zsh-users

Hi,

On 20 January 2011 22:02, Benjamin R. Haskell <zsh@benizi.com> wrote:
> Sorry.  I never saw this for some reason...

That's OK.  I like to leave time enough before asking again.  :)

> I'm not sure there's a nice way to do this.  I think
> history-beginning-search-* uses everything preceding the cursor as the
> search.  So, if you push the cursor to EOL, your search changes, which might
> not be desirable:
>
> e.g. history contains:
>
> abcdef 123456
> abcghi
> abcdef
>
> abc_ + the search would end up with: abcdef_ (cursor at end of line). Then
> 'abcghi' would be skipped in a successive search, even though it matches the
> original (abc), because it doesn't start with the new search (abcdef).
>
> Something more clever, that would maybe:
>
> 1. reset the 'search term' on accept-line
> 2. on first run, keep track of the 'search term'
> 3. run history-beginning-search-*

How might I go about implementing this?  My zsh knowledge is not too
good to implement steps 1-3 as you suggest.  Sorry, Ben.  :)

Michael


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

* Re: Completion style like Vim
  2011-01-20 22:14               ` Michael Treibton
@ 2011-01-23  4:56                 ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2011-01-23  4:56 UTC (permalink / raw)
  To: zsh-users

On Jan 20, 10:14pm, Michael Treibton wrote:
}
} On 20 January 2011 22:02, Benjamin R. Haskell <zsh@benizi.com> wrote:
} >
} > Something more clever, that would maybe:
} >
} > 1. reset the 'search term' on accept-line
} > 2. on first run, keep track of the 'search term'
} > 3. run history-beginning-search-*
} 
} How might I go about implementing this?  My zsh knowledge is not too
} good to implement steps 1-3 as you suggest.  Sorry, Ben.  :)

I think perhaps you just want the history-search-end widget which is
included in the zsh distribution?

"man zshcontrib" or "info zsh" and search for history-search-end:

    This function implements the widgets [which] work by first calling
    the corresponding builtin widget and then moving the cursor to the
    end of the line. The original cursor position is remembered and
    restored before calling the builtin widget a second time, so that
    the same search is repeated to look farther through the history.

-- 


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

end of thread, other threads:[~2011-01-23  4:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 19:57 Completion style like Vim Michael Treibton
2010-11-16 20:09 ` Benjamin R. Haskell
     [not found]   ` <AANLkTimqY0yVW-uHNi_pKMYRjTZJ7a1CamENMs2CpCQs@mail.gmail.com>
     [not found]     ` <alpine.LNX.2.01.1011161606310.2792@hp>
2010-11-16 21:21       ` Benjamin R. Haskell
2010-11-17 22:43         ` Michael Treibton
2011-01-20 21:02           ` Michael Treibton
2011-01-20 22:02             ` Benjamin R. Haskell
2011-01-20 22:14               ` Michael Treibton
2011-01-23  4:56                 ` 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).