[Grml] zsh history completion via arrow keys

Frank Terbeck ft at grml.org
Wed Jan 23 21:28:09 CET 2013

John wrote:
> It is active, but its behavior isn't what I'd like... For example:
> % vim ~/<<UPARROW>>
> Here are the first 4 responses to the above line:
> % vim PKGBUILD
> % vim build_time.txt
> % ~/.ssh/known_hosts
> % ~/bin/wake
> I want zsh to only show me responses in my history that begin with 'vim ~/' so
> in my example above, the first two would not show up at all.  Is there such a
> widget (without using that huge fishshell thing).

Heh.  Sorry for not reading your first posting thoroughly enough.

>From the zshcontrib(1) manual:

     up-line-or-beginning-search, down-line-or-beginning-search
          These  widgets are  similar  to  the builtin  functions
          up-line-or-search  and  down-line-or-search:  if  in  a
          multiline  buffer  they  move  up or  down  within  the
          buffer,  otherwise  they  search  for  a  history  line
          matching the start of the  current line.  In this case,
          however,  they  search for  a  line  which matches  the
          current line up to the  current cursor position, in the
          manner    of   history-beginning-search-backward    and
          -forward, rather than the first word on the line.

So, you'd probably need something along the lines of this:

  autoload -Uz up-line-or-beginning-search
  autoload -Uz down-line-or-beginning-search
  bindkey '\eOA' up-line-or-beginning-search
  bindkey '\e[A' up-line-or-beginning-search
  bindkey '\eOB' down-line-or-beginning-search
  bindkey '\e[B' down-line-or-beginning-search

Regards, Frank

More information about the Grml mailing list