
Just discovered grmlzshrc and am loving it. One thing I cannot seem to figure out though is how to enable zsh history completion on up arrow that reads what I have typed and only completes matches? For example, I type:
% vim ~/bin <<UPARROW>>
The expected behavior is to autocomplete entries that begin with 'vim ~/bin' but that isn't what happens. When I hit UPARROW the auto complete lists shows anything that started with 'vim ' which ignores the ~/bin bit.
I am using Arch Linux and the Distro provided grml-zsh-config package. The only configuration I have done is to copy /etc/skel/.zshrc to ~
Thank you!

John wrote:
Just discovered grmlzshrc and am loving it. One thing I cannot seem to figure out though is how to enable zsh history completion on up arrow that reads what I have typed and only completes matches? For example, I type:
% vim ~/bin <<UPARROW>>
The expected behavior is to autocomplete entries that begin with 'vim ~/bin' but that isn't what happens. When I hit UPARROW the auto complete lists shows anything that started with 'vim ' which ignores the ~/bin bit.
We actually do have
bindkey '\e[A' up-line-or-search
in there. However, we might need to do this too:
bindkey '\eOA' up-line-or-search
...keyboard handling is something that we want to improve for a long time. But it's not trivial to get right and especially to convert our existing bindings, without breaking backwards compatibility (too much).
Report if the additional binding enables that feature for you.
Regards, Frank

Report if the additional binding enables that feature for you.
Hi Frank. I added the line to my /etc/zsh/zshrc right under the original but upon opening a new terminal, the desired effect is not present.
Starting on line 671: bindkey '\e[A' up-line-or-search # cursor up bindkey '\eOA' up-line-or-search bindkey '\e[B' down-line-or-search # <ESC>-
If you have other thoughts, I am very interested.

John wrote:
I added the line to my /etc/zsh/zshrc right under the original but upon opening a new terminal, the desired effect is not present.
[...]
If you have other thoughts, I am very interested.
In your terminal, at the zsh prompt, hit Control-v followed by the up-cursor key. What does that insert into the command line?
Regards, Frank

In your terminal, at the zsh prompt, hit Control-v followed by the
up-cursor key. What does that insert into the command line?
I recently discovered fishshell.com which has a very nice implementation of this feature. See: https://github.com/graysky2/configs/blob/master/shell/.zsh/lib/substring-sea...

John wrote: [...]
I recently discovered fishshell.com which has a very nice implementation of this feature.
Maybe so, but too big to include for my taste. But it looks like that should work on top of our zshrc just fine. So use it if you like it.
However it only binds to these sequences:
bindkey '\e[A' history-substring-search-up bindkey '\e[B' history-substring-search-down
So that won't help your problem at hand. (Then again, I just told you in the other mail how to find out about the actual escape sequence our terminal emits when you hit the up-cursor key; so you can fix that on you own now).
Regards, Frank

John wrote:
In your terminal, at the zsh prompt, hit Control-v followed by the
up-cursor key. What does that insert into the command line?
Dunno how I missed this post. The output you requested:
^[[A (up arrow)
Well, in that case, this binding should be invoked and things should work:
bindkey '\e[A' up-line-or-search
To make sure, what does this yield?
% bindkey '<CTRL-v><Up-Arrow>'
(Press the actual keys, don't just paste that line.)
Regards, Frank

Well, in that case, this binding should be invoked and things should
work:
bindkey '\e[A' up-line-or-search
To make sure, what does this yield?
% bindkey '<CTRL-v><Up-Arrow>'
(Press the actual keys, don't just paste that line.)
Hello Frank - Here I have removed the fishshell mod that I posted and am back to the modifed grml config. Recall that I modified it per your suggestion to add the following to /etc/zsh/zshrc
bindkey '\e[A' up-line-or-search # cursor up
bindkey '\eOA' up-line-or-search bindkey '\e[B' down-line-or-search # <ESC>-
Here is the output of the command you asked about:
% bindkey '"^[[A" up-line-or-search
Thank you!

John wrote: [...]
Here is the output of the command you asked about:
% bindkey '"^[[A" up-line-or-search
So, `up-line-or-search' is indeed active already. Isn't this what you asked for? From the manual:
up-line-or-search Move up a line in the buffer, or if already at the top line, search backward in the history for a line beginning with the first word in the buffer.
If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.
Regards, Frank

So, `up-line-or-search' is indeed active already. Isn't this what you
asked for? From the manual:
up-line-or-search Move up a line in the buffer, or if already at the top line, search backward in the history for a line beginning with the first word in the buffer.
If called from a function by the zle command with arguments, the first argument is taken as the string for which to search, rather than the first word in the buffer.
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).
Thanks!

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

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
OK! I placed those 6 lines in my ~/.zshrc.local and resourced the config file. The key mapping seems intact:
% bindkey '"^[[A" up-line-or-beginning-search
But if I attempt to use the uparrow now, I get:
% vim ~/ :( No such widget `up-line-or-beginning-search'
You thoughts are welcomed and thank you.

John wrote: [...]
But if I attempt to use the uparrow now, I get:
% vim ~/ No such widget `up-line-or-beginning-search'
Meh. This is what I get for not trying things out...
autoload -Uz up-line-or-beginning-search zle -N up-line-or-beginning-search autoload -Uz down-line-or-beginning-search zle -N 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
There seems to be a cosmetic bug that triggers the first time you use either of those (if you got warn_create_global set, which I do):
up-line-or-beginning-search:15: scalar parameter __savecursor created globally in function up-line-or-beginning-search:16: scalar parameter __searching created globally in function
you can do the following until you get a fixed up zsh version:
typeset -g __savecursor __searching
Regards, Frank

Meh. This is what I get for not trying things out...
autoload -Uz up-line-or-beginning-search zle -N up-line-or-beginning-search autoload -Uz down-line-or-beginning-search zle -N 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
There seems to be a cosmetic bug that triggers the first time you use either of those (if you got warn_create_global set, which I do):
up-line-or-beginning-search:15: scalar parameter __savecursor created globally in function up-line-or-beginning-search:16: scalar parameter __searching created globally in function
you can do the following until you get a fixed up zsh version:
typeset -g __savecursor __searching
The 8 lines you posted works without the typeset bit. Thank you. I think others would like this functionality. Perhaps add it as a the grml default?

John wrote: [...]
The 8 lines you posted works without the typeset bit.
Then you don't have the warn_create_global option set. Which is ok, I guess. I'm going to fix it upstream anyway.
Thank you.
You're welcome.
I think others would like this functionality. Perhaps add it as a the grml default?
I don't think we should wiggle around with the default settings too much. Things like this are pretty much up to anyone's subjective preferences, which is exactly why we do have facilities like zshrc.local and zshrc.pre in place.
Regards, Frank

Frank Terbeck wrote: [...]
I don't think we should wiggle around with the default settings too much. Things like this are pretty much up to anyone's subjective preferences, which is exactly why we do have facilities like zshrc.local and zshrc.pre in place.
Also, it turns out, that we already do have a binding that does basically the same on <PageUp> and <PageDown>. So.... :)
(Missing this serves me right for not using our zsh setup myself...)
Regards, Frank

Meh. This is what I get for not trying things out...
autoload -Uz up-line-or-beginning-search zle -N up-line-or-beginning-search autoload -Uz down-line-or-beginning-search zle -N 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
One last question for you, Frank. In the interest of maintaining a minimal configuration, are all 8 lines required for this functionality? My setup is the out-of-the-box grml configuration: *Unmodified /etc/zsh/zshrc *Unmodified /etc/skel/.zshrc (in my $HOME) *8 line $HOME/.zshrc.local
Thanks again.

John wrote:
autoload -Uz up-line-or-beginning-search zle -N up-line-or-beginning-search autoload -Uz down-line-or-beginning-search zle -N 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
One last question for you, Frank. In the interest of maintaining a minimal configuration, are all 8 lines required for this functionality? My setup is
Well, you _could_ leave out the two lines that contain bindings for '\eOA' and '\eOB'. But those make things work in more terminals. So you should probably keep them anyway.
the out-of-the-box grml configuration: *Unmodified /etc/zsh/zshrc
That one you need. And you shouldn't modify it indeed.
*Unmodified /etc/skel/.zshrc (in my $HOME)
This one, you could leave out, because it's just a set of examples, that are all commented out...
*8 line $HOME/.zshrc.local
...and since you should do all modifications via this file, you should also put those examples from the skel file into .zshrc.local.
Regards, Frank
participants (2)
-
Frank Terbeck
-
John