How to set tab for zsh autocompletion?
Asked Answered
B

5

19

I want to set tab for zsh autocomplition plugin. There is related part of config:

# Widgets that accept the entire suggestion
(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
        typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
        ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
                forward-char
                end-of-line
                tab-char //my line
                vi-forward-char
                vi-end-of-line
                vi-add-eol
        )
}

What is the convention for char names used? How does tab named?

Bever answered 28/11, 2019 at 18:50 Comment(0)
H
15

You will have to put

bindkey '       ' autosuggest-accept

into your .zshrc file. Notice that the space between the apostrophe is one keystroke of the tab-character. This works similarly with every other character or character combination. If you for example wanted to put a combination of the ctrl+space keys to trigger the acception, you'd append

bindkey '^ ' autosuggest-accept

to the file.

Here's a link to the Configuration-file, where this is explained: https://github.com/zsh-users/zsh-autosuggestions#key-bindings

Hamm answered 28/11, 2019 at 22:6 Comment(3)
and how to bind tab?Bever
I think you have one more space or something, I have copy pasted and it wasn't working. The best way is to directly type bindkey '' autosuggest-accept and then place the cursor in between the tick and press tab.Incardination
Note that typically modern editors are set to expand the tab key to spaces, which would prevent this from working.Fdic
S
31

For all of you that are struggling with the accepted answer, I got it to work doing the following:

bindkey '^I' autosuggest-accept

...where '^I' is tab.

Skeptical answered 25/2, 2021 at 6:9 Comment(3)
This worked for me. +1.Viviparous
I guess it's showing ^I because you are using vim and used :set listJumbled
on Mac M1, I needed to do bindkey '^I' expand-or-completeKentigera
H
15

You will have to put

bindkey '       ' autosuggest-accept

into your .zshrc file. Notice that the space between the apostrophe is one keystroke of the tab-character. This works similarly with every other character or character combination. If you for example wanted to put a combination of the ctrl+space keys to trigger the acception, you'd append

bindkey '^ ' autosuggest-accept

to the file.

Here's a link to the Configuration-file, where this is explained: https://github.com/zsh-users/zsh-autosuggestions#key-bindings

Hamm answered 28/11, 2019 at 22:6 Comment(3)
and how to bind tab?Bever
I think you have one more space or something, I have copy pasted and it wasn't working. The best way is to directly type bindkey '' autosuggest-accept and then place the cursor in between the tick and press tab.Incardination
Note that typically modern editors are set to expand the tab key to spaces, which would prevent this from working.Fdic
I
13

In the .zshrc file:

bindkey '^I'   complete-word       # tab          | complete
bindkey '^[[Z' autosuggest-accept  # shift + tab  | autosuggest

https://github.com/zsh-users/zsh-autosuggestions/issues/532#issuecomment-907361899

Intromit answered 7/1, 2022 at 16:56 Comment(2)
complete-word works for me. Thanks!Gormand
This is great. Works on Mac and is exactly the right combination to use zsh-autocomplete and zsh-autosuggestions together.Cavill
W
8

this seems to work as expected in your ~/.zshrc:

bindkey '\t' autosuggest-accept

If you want to know more, you can click here

Wembley answered 25/11, 2021 at 6:50 Comment(1)
This was the only solution that worked for me. On Ubuntu 22LTS, Gnome and VSCode.Contagion
H
6

I know this is a bit old, but leaving it here for those who try to use this later.

What I am using is

bindkey '^I^I' autosuggest-accept

If I press tab key twice in succession, it completes the command. If I tap tab once and leave I can use the shell's suggestions and cycle through them.

Hemphill answered 16/5, 2023 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.