zsh-autocomplete icon indicating copy to clipboard operation
zsh-autocomplete copied to clipboard

Hide "all matches" completion because of limited utility and poor performance

Open unphased opened this issue 2 years ago β€’ 12 comments

Environment

ubuntu linux-gnu /usr/bin/zsh -zsh ubuntu/5.8-3ubuntu1.1
/home/slu/.zshrc:70
7ab87cb (HEAD -> main, origin/main, origin/HEAD) Remove the Zsh version checks
  • Operating system: Ubuntu 20.04
  • Terminal emulator: alacritty

Steps to reproduce

Ran the following commands:

❯ cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 59 (delta 0), reused 25 (delta 0), pack-reused 0
Unpacking objects: 100% (59/59), 1.64 MiB | 13.43 MiB/s, done.
% cd /home/slu
% vim three.js/build three.js/docs three.js/editor three.js/examples three.js/files three.js/manual three.js/node_modules three.js/src three.js/test three.js/utils three.js/LICENSE three.js/README.md three.js/icon.png three.js/package-lock.json three.js/package.json
file
package-lock.json  package.json
all matches
package-lock.json package.json

I typed:

  • cd /home/slu
  • vim
  • space
  • thr
  • tab
  • shift+tab

Note shift+tab is bound with terminal emulator to <Esc>[Z.

unphased avatar Apr 06 '22 06:04 unphased

Another one:

❯ cd $(mktemp -d) 
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 59 (delta 0), reused 25 (delta 0), pack-reused 0
Unpacking objects: 100% (59/59), 1.64 MiB | 17.13 MiB/s, done.
% ls
zsh-autocomplete
% cd /home/slu
% echo .
directory
.Superposition/     .Xauthority/  .ansible/  .anydesk/   .cache/  .cargo/   .config/        .dbus/  .debug/  .designer/  .dive.yaml/  .docker/  .dropbox/  .dropbox-dist/         .fonts/  .fzf/       .gem/      .gnome/                   .gnupg/                   .gphoto/   .lldb/  .local/  .marvim/  .mozilla/  .npm/  .nv/
.nvidia-omniverse/  .oh-my-zsh/   .pki/      .pylint.d/  .ros/    .rustup/  .screenlayout/  .ssh/   .ssr/    .steam/     .terminfo/   .tmp/     .tmux/     .tmux-resurrect-save/  .vim/    .visidata/  coc.nvim/  node-v12.22.1-linux-x64/  node-v14.15.5-linux-x64/  three.js/
file
2021-05-17\ 21-30-31.mkv  2021-05-17\ 21-30-31.mp4  2021-05-18\ 15-08-42.mkv  2021-05-18\ 15-08-42.mp4  2021-05-18\ 15-08-53.mkv  2021-05-18\ 15-08-53.mp4  2021-05-21\ 13-06-47.mkv  2021-05-21\ 13-06-47.mp4  2021-05-25\ 12-39-46.mkv  2021-05-25\ 12-39-46.mp4   2021-05-25\ 14-56-37.mkv  2021-05-25\ 14-56-37.mp4  2021-05-27\ 01-00-16.mkv
2021-05-27\ 01-00-16.mp4  2021-05-27\ 01-15-41.mkv  2021-05-27\ 01-15-41.mp4  2021-05-27\ 19-22-22.mkv  2021-05-27\ 19-22-22.mp4  2021-06-10\ 00-42-39.mkv  2021-06-10\ 00-42-39.mp4  2021-06-10\ 00-43-14.mkv  2021-06-10\ 00-43-14.mp4  2021-06-10\ 00-55-13.mkv   2021-06-10\ 00-55-13.mp4  2021-06-10\ 15-18-43.mkv  2021-06-10\ 15-18-43.mp4
2021-06-10\ 15-19-19.mkv  

I typed

  • cd /home/slu
  • echo .
  • tab
  1. Why is .Superposition the first entry shown in the directories completion? It should probably be .alacritty.yml. It must be just that uppercase chars come first in the sort. Any way to fix this to be consistent with regular zsh behavior?
  2. (not a complaint. I know it is default behavior) Hitting tab one more time starts completing inside ~/.Superposition, I understand this to be due to the default setting of zstyle ':autocomplete:*' widget-style complete-word. A perplexing choice though that is only an opinion.

unphased avatar Apr 06 '22 06:04 unphased

You need to set zstyle ':autocomplete:*' widget-style menu-complete or menu-select to get the behavior you want.

Zsh Autocomplete does not change the default sort order of files. Please see the Zsh completion system manual for info on how to change the sort order of file completions. Alternatively, try changing the value of $LC_COLLATE on your system.

marlonrichert avatar Apr 11 '22 14:04 marlonrichert

I already was using zstyle ':autocomplete:*' widget-style menu-select. OK i'll test it some more using the reproduction method.

unphased avatar Apr 11 '22 17:04 unphased

@unphased Note that you need to set it before sourcing Zsh Autocomplete. Setting it at runtime doesn’t work.

marlonrichert avatar Apr 12 '22 07:04 marlonrichert

I did have it included before, and zstyle ':autocomplete:*' widget-style menu-select definitely had the intended effect, that is to make the tab not commit to the first suggestion.

Maybe I haven't been clear in my explanation. When using the repro steps it's clear that it just clones a fresh autocomplete plugin and runs it on a raw zsh. Even in this state the completion ordering is inconsistent with when you press tab on a clean zsh (It favors uppercase dotfiles shown by my example).

The second issue is shift+Tab when it cycles around it will dump all completions into the command buffer, which can't be right, is it?

unphased avatar Apr 12 '22 19:04 unphased

shift+Tab when it cycles around it will dump all completions into the command buffer

But if you press Shift-Tab again, does it then remove them?

marlonrichert avatar Apr 13 '22 16:04 marlonrichert

But if you press Shift-Tab again, does it then remove them?

It does not.

Are you able to reproduce based on my instructions?

unphased avatar Apr 13 '22 18:04 unphased

I'm able to reproduce both test cases that you presented, but both of these show only expected behavior.

By default, Tab inserts the top entry and Shift-Tab inserts the bottom entry, and new completions are listed immediately afterwards.

With `zstyle ':autocomplete:*' widget-style menu-select, the top and bottom entry, respectively, are inserted, too, but no new completions are generated and you can replace what's inserted on the command line with the next or previous entry, by pressing Tab or Shift-Tab (again), respectively.

So, in other words: I don't see any bug here.

marlonrichert avatar Apr 14 '22 06:04 marlonrichert

I understand this to be due to the default setting of zstyle ':autocomplete:*' widget-style complete-word. A perplexing choice though that is only an opinion.

That's subjective β€” and because it's subjective, I've provided a zstyle with which you can change it. By default, Zsh Autocomplete tries to make shell completion work β€” as much as possible β€” like it does in modern IDEs, where pressing Tab insert the top match. If you want to insert another match, just keep typing until it's the top match β€” or use the down arrow key to enter the menu and then use the arrow keys to select a different match.

marlonrichert avatar Apr 14 '22 06:04 marlonrichert

like it does in modern IDEs, where pressing Tab insert the top match. If you want to insert another match, just keep typing until it's the top match β€” or use the down arrow key to enter the menu and then use the arrow keys to select a different match.

I'm not sure about this. I think that in most IDEs if you press tab once it may well fill the first completion item into the buffer for you but when you press tab the second time after that it will switch it into the second item in the completion list. Right? Happy to be corrected. Since I spend the majority of my editing time inside vim.

able to reproduce both test cases

In the first test case, the keystrokes I described

  • vim
  • space
  • thr
  • tab
  • shift+tab

produced a command line of:

vim three.js/build three.js/docs three.js/editor three.js/examples three.js/files three.js/manual three.js/node_modules three.js/src three.js/test three.js/utils three.js/LICENSE three.js/README.md three.js/icon.png three.js/package-lock.json three.js/package.json

Where I was in a dir that has a three.js git repo dir inside it. Now surely this behavior is not expected.

I hear you on the default tab behavior, and it seems fine (just use arrow keys to select the suitable completion item, sure) but I'm not seeing why typing shift+tab should dump everything in. Surely my keystrokes should result in just:

vim three.js/package.json

? The reasoning being:

  • first tab completes three.js/
  • shift+tab pulls last completion item which is the last one in the list, the package.json file

unphased avatar Apr 14 '22 09:04 unphased

OK... I'm dumb and wasn't paying attention. There is a completion result group called all matches and that is the last one and is what shift+tab selects. So I finally understand now what you mean that this is expected. I can see this being useful as well, just never would have wanted to do this with a completion workflow since globs seem so natural. Sorry about that misunderstanding.


I also now cannot reproduce the other thing I complained about, the upper case hidden dot directory from being the first completion. This is weird, oh well.

unphased avatar Apr 14 '22 09:04 unphased

globs seem so natural

That's a good point. Also, the "all matches" completion is incredibly slow to insert, especially when you also have syntax highlighting installed. I think maybe I'll just remove it. I never seem to find any use for it either.

marlonrichert avatar Apr 14 '22 14:04 marlonrichert