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

Re: Line editor - "get word from history"



Paul Moore wrote:
> I was reading an article on the WWW recently, which compared various
> shells. One feature of tcsh which was commented on favourably was the
> history stuff. Two particular features I liked:
> 
> 1. A keypress to move to a previous history line which matched what you
> had typed so far on the line. Zsh has this, in history-beginning-search-
> backward (although I'd prefer this if it moved the cursor to the end of
> the line, but retained knowledge of the part I had typed, so that I
> could continue backwards matching what I had typed, or stop and add to
> the end of the line).

There's a long and involved story to this.  The end of the story is
that zsh had this, but it was removed because it seemed to be one too
many special cases in the Zle code.  The dust has not yet quite
settled.  Frankly, having seen all the discussion, I think the path of
least resistance is to put it back in some form.

Having converted myself, I can say, however, that when you get used to
it not going to the end of the line you may wonder why you ever wanted
it to.

> 2. A keypress to complete the current word, using the words in previous
> history lines - imagine 
>     mkdir a-very-long-name
>     cd a-<complete>
> 
> I looked in the zsh documentation I have (not totally up-to-date) and
> could find nothing like (2). Is it available in the latest version, and
> if not, is there any chance of it being added?

It's not there as such in an official version yet, but there are two
notes to be made (three notes to be made, among the notes to be made
are):

1. there are better ways of completing directory names in both tcsh
and zsh, but I presume that was just a random example.

2. you can in all recent zsh add history matching to default
completion (or any other sort) by sticking + -H 0 '' on the end,
e.g. (simplest case):
  compctl -D -f + -H 0 ''
so if it doesn't find a file it'll search the history list.

3. there is a patch which allows you to bind arbitrary completions to
particular keys.  If you're desperate to try it, there's an unofficial
(and definitely beta, though apparently usable) version which contains
it which you can get at
http://www.ifh.de/~pws/computing/zsh-3.1.5-patched.tar.gz .
Then the incantation is
  zle -C history-complete-word -H 0 ''
  bindkey "your-favourite-key-sequence" history-complete-word
This method works for any set of completions, not just history.  The
semantics may change if this patch becomes official.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56100 Pisa, Italy



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