3

I am currently attempting to create a custom colorscheme for vim by using ctermfg and ctermbg values, and checking what the colorscheme looks like with the highlight test file provided by Vim.

What I do not understand is why ctermfg and ctermbg appear backwards, and also incorrect, for certain highlighting groups. StatusLine, for instance, is set to have a black foreground and a white background, but instead has a white foreground and a gray background. Is there something special about specific highlighting groups that I should keep in mind when I set their colors?

enter image description here

5

You're probably overlooking the additional attributes set in the cterm= field for those highlights.

For instance, after I set ctermfg=black ctermbg=white for StatusLine, I get this when I query it:

:hi StatusLine
StatusLine     xxx term=bold,reverse cterm=bold,reverse
                   ctermfg=0 ctermbg=15 gui=bold,reverse

You'll see the cterm=bold,reverse there, which is part of the defaults for StatusLine. In particular, reverse will swap fg & bg colors, which is the effect you're seeing.

Since those attributes are set in a separate field (cterm=), which you're not overriding, the defaults are being preserved.

To undo the effects of this field, you could set it explicitly, with:

hi StatusLine cterm=bold

Or, to also drop the bold attribute:

hi StatusLine cterm=reverse

Or you could just decide to embrace the default of using reverse colors on the StatusLine and perhaps some other highlight groups and just set your fg & bg colors in reverse, to then have the reversing applied by cterm= get the colors as you actually want them. 🙃

Also consider the term= (for B&W terminals) and gui= (for gvim) attributes, if you're considering setting custom highlighting that you'd like to work on those environments as well.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.