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

Re: Completion style like Vim

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:


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


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:


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

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.


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