Zsh-autosuggestions: Use <tab> to choose autosuggestion

Created on 14 May 2020  路  11Comments  路  Source: zsh-users/zsh-autosuggestions

Is your feature request related to a problem? Please describe.


When I start typing a command, and zsh shows an autosuggestion, is it possible to choose the autosuggestion by pressing the tab key or some other key instead of the right arrow key?
Moving my hand all the way to the right arrow key is slow, so is everyone only using the right arrow key to choose the autosuggestion?

Describe the solution you'd like


Pressing tab when an autosuggestion hint is shown should just choose the shown autosuggestion.

support

Most helpful comment

This is possible by adding this to your .zshrc:

bindkey '\t' end-of-line

All 11 comments

This is possible by adding this to your .zshrc:

bindkey '\t' end-of-line

I personally don't use it though, because sometimes the default tab behaviour is useful, like choosing directories

Yeah that's true.
So does everyone just move their hand all the way to the right arrow key then? Does anyone have a better method instead of overriding the tab key?

Well if you don't want to use right arrow key then you can put any other key instead of tab in that code I pasted above.

Btw also, I realized that you can do this

export ZSH_AUTOSUGGEST_STRATEGY=(
    history
    completion
)

Which allows the preview to fallback on using tab completion when there is no matching history. This is pretty nice when choosing directories. Which makes those times when you really need tab a bit less common.

Edit: After using this for awhile I ended up deleting it since it can be slow sometimes

I mostly use ^E for end-of-line (in emacs mode)

thx

I mostly use ^E for end-of-line (in emacs mode)

I'm use

bindkey '^I'      autosuggest-accept
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(buffer-empty bracketed-paste accept-line push-line-or-edit)
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_USE_ASYNC=true

tab - history completion
shift+tab - autosuggest completion

@mindyourlifeguide did you write that incorrectly?
I tried using that, but it makes tab do autosuggest completion, and shift+tab do history completion backwards.

How would I invert the tab and shift+tab from those lines you pasted?

Specifically, I tested that while using cd
$ cd <completion shows a previous cd command>
If I use tab, it accepts it.
But I usually press tab to see all the subdirs in this dir and cycle through them, so I don't want to lose that behavior.

Specifically, I tested that while using cd
$ cd <completion shows a previous cd command>
If I use tab, it accepts it.
But I usually press tab to see all the subdirs in this dir and cycle through them, so I don't want to lose that behavior.

I wrote the combinations that I use)
These are right for you:

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

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

 bindkey '\t' autosuggest-accept
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mindyourlifeguide picture mindyourlifeguide  路  6Comments

guitaristtom picture guitaristtom  路  6Comments

mehedi-sharif picture mehedi-sharif  路  6Comments

NikKovIos picture NikKovIos  路  4Comments

OmeGak picture OmeGak  路  3Comments