Syntax highlighting in zsh using 256 colors?


I’m using prezto with zsh, and my difficulty is with the syntax highlighting, of which a sample line is

'function' 'bg=green'

I could also have here, for example

'function' 'bg=blue,fg=yellow'

However, I want to take advantage of my 256 color terminal (konsole in my case), in which case I would have thought that something like

'function' 'bg=$FG[021],fg=$FG[196]'

for example, would work, given that I have previously loaded the spectrum module.

But I can’t get this to work. I’ve checked that tput colors returns 256, and that the command

 echo "$FG[214]Hello, World"

gives me an orange output.

Anyway, whether I use spectrum or not, I’d like more control over my syntax highlighting, and to be able to use 256 colors. Any advice would be very welcome!


You could specify the color index here like below:

'function' 'bg=21,fg=196'

zsh-syntax-highlighting gets the ability to specify colors from the zsh’s Character Highlighting rather than ANSI escape sequences directly. This zsh manual describes a ‘fg=colour‘ as below:

 The foreground colour should be set to colour, a decimal integer or the name of one of the eight most widely-supported colours.

We can use the color index rather than ANSI escpape sequences which spectrum module stores on $FG[...].

Answered By – hchbaw

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.