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

Allow Tab and Shift-Tab to be disabled or reassigned

Open SephVelut opened this issue 3 years ago • 7 comments

I'm using zsh-autosuggestions and it allows me to use its completion with tab and shift+tab. I like it's completion. But I also want to use autocomplete. The problem is that this plugin also uses tab and shift+tab. How can I disable those two keys for autocomplete?

I tried

 zstyle ':autocomplete:*' bindkey no

and

 zstyle ':autocomplete:*' bind-key no

SephVelut avatar Feb 19 '22 11:02 SephVelut

It's currently not possible to disable or reassign Zsh Autocomplete's Tab and Shift-Tab functionality. I'll have to think about what would be the best way to make this possible.

marlonrichert avatar Feb 20 '22 19:02 marlonrichert

As a workaround, you can add the following to your .zshrc file, after sourcing Zsh Autocomplete:

add-zsh-hook precmd bind-tab
bind-tab() {
  bindkey '\t' <your preferred tab widget>
  bindkey $terminfo[kcbt] <your preferred shift-tab widget>
}

@SephVelut @LoLei @Alex-duzhichao @crushingCodes @AndreCascais @mjrussell

marlonrichert avatar Apr 20 '22 13:04 marlonrichert

@marlonrichert A bit of a followup question/request, I would also like to disable or tweak the Tab behavior.

If you have the following directories:

foo1
foo2
foo3

The moment I write cd fo and press Tab, I want it to autocomplete cd foo rather than cd foo1.

Is there any possibility for that?

lordzsolt avatar Jun 08 '22 12:06 lordzsolt

@lordzsolt Yes, that’s possible. Just set the following setting to yes: https://github.com/marlonrichert/zsh-autocomplete/blob/5b0073d8ffde20498c820f94ddc62b7f3f54cfc7/.zshrc#L37

marlonrichert avatar Jun 13 '22 06:06 marlonrichert

@marlonrichert I also am trying to achieve the same thing as @lordzsolt however your suggestion of setting insert-unambiguous to yes is not making any difference for me.

oldo avatar Aug 11 '22 23:08 oldo

@oldo Works for me:

% cd $(mktemp -d)
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source /path/to/zsh-autocomplete.plugin.zsh
zstyle ':autocomplete:*' insert-unambiguous yes
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d

Please use the above to create a reproducible test case. If I can't reproduce it, then I can't fix it.

marlonrichert avatar Aug 17 '22 07:08 marlonrichert

I just realized what would be a good way to give more control over Tab and Shift-Tab assignment: Just don't override the current keybinding.

I'll add this to my TODO list.

marlonrichert avatar Aug 25 '22 07:08 marlonrichert

I haven't found the time to implement this yet. It's not complex, though. The following should be done:

  • [ ] If the currently supported zstyle for this has been set, use that (for backwards compatibility.
  • [ ] Remove the zstyle from the docs.
  • [ ] If it hasn't been set, then don't override the current keybindings.
  • [ ] Add this to the documentation.

Pull requests welcome! 🙂

marlonrichert avatar Sep 27 '22 13:09 marlonrichert