Search code examples
zshtab-completioncompletion

zsh’s tab completion overwrites what's next


If I write some command line and I forget to put something in the middle, I normally go back and start typing there

% command --option -s █  --something-else
                      ^ cursor

Then I might want to use the autocomplete feature, so I press TAB. In my configuration (which I'll post below) two things can happen:

  1. If there is only one option, the expected behavior happens
(type "lon")
% command --option -s lon█  --something-else
(press TAB)
% command --option -s long_folder/█  --something-else
  1. If there are multiple options the first TAB press will show a list of alternatives and any arrow key will write the first alternative in the command line. Unfortunately, if I do this, the following text is not shifted but rather overwritten
% command --option -s lon█  --something-else
(press TAB)
interactive: lon[]
long_folder/  loong_folder/  whatever/
(press arrow down)
% command --option -s long_folder/█hing-else

As you can see pressing TAB overwrites part of what was next. How to avoid this?


Relevant part of my .zshrc

autoload -Uz compinit
compinit

setopt noautomenu
setopt globcomplete
bindkey '^i' complete-word
setopt nolisttypes

zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu yes select interactive

The last line is responsible for this behavior.


Solution

  • I can confirm that that’s a bug in zsh. I’ve submitted a bug report on the Z Shell mailing list about it.