Syntax highlighting in zsh using 256 colors?

1.3k views Asked by At

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!

2

There are 2 answers

1
hchbaw On BEST ANSWER

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:

fg=colour
 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[...].

0
nitishagar On

You can try:

export TERM='xterm-256color'