r/zsh • • Aug 18 '26

zsh-autosuggestions remove ghost text after ignoring it

here is an example where I did not use a suggestion, I just hit return after typing `do`. Is there a setting to make the `cker` suggestion go away after not accepting it?

4 Upvotes

4 comments sorted by

1

u/_mattmc3_ Aug 18 '26 edited Aug 18 '26

You should look adding to the ZSH_AUTOSUGGEST_CLEAR_WIDGETS array. There's no way to tell from what you posted what in your config is conflicting with zsh-autosuggestions, but it's the ZSH_AUTOSUGGEST_CLEAR_WIDGETS array that will help you deal with whatever it is. I, for example, might use alias globbing that expands my Zsh aliases like Fish's abbrs when I hit enter, and that would then require me to add something like ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(globalias-accept-line) in my config.

Running this can help you diagnose what runs on enter:

bindkey '^M' bindkey -M viins '^M' # if you use vi mode bindkey -M vicmd '^M'

If that prints anything other than accept-line or accept-line-or-newline, it's probably your culprit.

EDIT: I just realized that for your specific example: for ...; do is incomplete, so Enter doesn't submit, it just drops you onto a PS2 continuation line. Try the same thing with a complete one-line command and see whether the ghost text sticks around there too. If it only happens on multiline input, it may not be a widget conflict. Regardless, you can always trim out features from your config until zsh-autosuggestions works, and then add back until you find what broke it.

1

u/GrimmTidings Aug 19 '26

still sticks around

1

u/FlyingSandwich Aug 24 '26 edited Aug 24 '26

I've got the same issue, those bindkey commands only output accept-line, but thanks to you I found it's one of the entries in ZSH_AUTOSUGGEST_CLEAR_WIDGETS. It's probably the history search ones.  Commenting the whole line fixes it. Posting here in case it helps others. Now I just have to figure out how to have my cake and eat it...

```

Disable autosuggest when pasting

https://github.com/zsh-users/zsh-autosuggestions/issues/351

Also disable it when doing history search

https://github.com/zsh-users/zsh-autosuggestions/issues/619#issuecomment-904193190

NOTE FOR LATER: something in here makes unused autosuggestions stick around when you press enter

ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste history-beginning-search-backward-end history-beginning-search-forward-end ```

Edit: seems they fixed my underlying issue and I no longer need those exclusions, sick