Reputation: 90
How can I configure zsh-autocomplete
to insert up to the longest common prefix, excluding their common suffixes?
I have not seen this asked before on StackOverflow. Here is a GitHub issue which is related but not the same.
I have a directory with the following files:
❯ ls -1
foo_a.sh
foo_b.sh
With the zsh-autocomplete
plugin enabled (branch main
-> commit 6d059a3
), typing ls f
shows the following:
❯ ls f
file
foo_a.sh foo_b.sh
common substring: foo_.sh
Note common substring: foo_.sh
, which comes from zsh-autocomplete
. This "common substring" consists of the prefix foo_
and suffix .sh
common to all files in the directory.
Pressing tab inserts that "common substring" into my command:
❯ ls foo_.sh # cursor is now at the end after h
file
foo_a.sh foo_b.sh
That completion is not useful at all, because it also inserts the suffix. There is no file called foo_.sh
!
Now I have to identify the disambiguating characters between the prefix and suffix, figure out where in the "common substring" they must be inserted, arrow back to that position, insert them, then arrow back to the end to continue the command.
That's a lot of work. Who wants that?
Much better would be to have tab insert only the common prefix:
❯ ls foo_
file
foo_a.sh foo_b.sh
Then I just need to add a
or b
, and a second tab will complete the rest of the filename. No need to move my cursor back and forth.
By the way, I believe that this is the default tab completion behavior in zsh. For some reason, zsh-autocomplete
seems to override it.
How can I configure zsh-autocomplete
to work the same way?
Upvotes: 3
Views: 264