Changing zsh-autosuggestions color

I have installed zsh-autosuggestions plugin in oh-my-zsh.
I'd like to change the colour of the text which comes in suggestion. My current color is very similar to that of what comes before.

Please see the image below.

enter image description here

This setting is probably govern by ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE setting. But when I add e.g. ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=60' the following happens:

enter image description here

What I'd like to have is bin in much different color than cd.

3

4 Answers

Refer to the official documentation available on GitHub:

Set ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE to configure the style that the suggestion is shown with. The default is fg=8, which will set the foreground color to color 8 from the 256-color palette. If your terminal only supports 8 colors, you will need to use a number between 0 and 7.

Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"

For more info, read the Character Highlighting section of the zsh manual: man zshzle or online.

Note: Some iTerm2 users have reported not being able to see the suggestions. If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black aredifferent.

So, you can change the colour of the suggestions and make them bold (maybe even underlined).

Modify the ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE to:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#d787ff,bold'

It'll make it appear much brighter than before.

You might want to change it to some other colour, for example, Cyan:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#00ffff,bold'

You might like underlining the suggestion:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#00ffff,bold,underline'

For the colour chat refer to the colour palette.

1

You can use:

# Change <your color> to a valid color
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=<your color>"
# For example, to make the text red:
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000"

The result will be like below, depending on the config you actually used:ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000"

You can append that line of setting to .zshrc.

EDIT: It is also possible to do almost any formatting on the suggested text. Here are some examples.ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000,bg=#00ff00,underline"ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000,bg=#00ff00,underline,standout,bold"

For a full list of formatting syntax, see it's official documentation. Hope you enjoy the reformatted texts and have a good day!

First I'd start with a setup the author uses:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"

Test this elaborate highlighting first and if it works, then dial it down to your preferences.


Also there is a setup issue reported on GitHub that might be effecting you:

Please read the entire thread but the most important part is below:

It turns out the zsh-syntax-highlighting plugin is conflicting somehow. I commented it out and everything worked as expected.

exec zsh, instead of sourcing .zshrc also works so I'll use that

I always use this color for contrast in terminals: (in my .zshrc file, I'd add)

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#00FF00,bold"

You're getting the color that you selected... 60 is a light magenta-ish color. I cut and pasted the script from here into my terminal and it output the color chart on that page to my terminal... displaying your "60" selection...

If I wanted to use those kind of codes to set my color preference, I'd do something like:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=46,bold"

...and get a similar result to the hex/rgb code in my 1st example above.

(in other words, there's nothing wrong, you're just picking a color you don't want.... pick another color, the chart(s) in the link above should help)

echotc Co will tell you how many colors your terminal supports, but I doubt you're going to need to verify that because you are getting the correct color for "60", so it is most likely 256.

Edit: I didn't realize there were so many charts and scripts on that page in the link. I just used the accepted answer from Tom Hale...

enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like