greduan
greduan

Reputation: 4938

How to find out a certain color value the current colorscheme is using for certain stuff?

I need this in order to finish a plugin I'm making in order to change the colors of the statusline depending on the mode.

However I've run across an obvious problem, how would I know what theme the user is using? And even if I knew I can't make specific colors for each theme.

So, how to know the foreground and background colors that the current theme is using for the statusline for example.

EDIT 1:

In case I wasn't clear, I'm looking for a way to find out the ctermfg/bg and guifg/bg for certain stuff. Right now the statusline. :)

EDIT 2:

Apparently if I do :hi StatusLine I get what I need, however I need to refine it to get only the value, and not all of it. Guess I'll have to use some regex to find out the value. If anybody knows an easier way please share it (or if you already figured it out with the regex). Thanks!

Upvotes: 10

Views: 2269

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172510

You can use the synIDattr() function to query the various attributes (like foreground and background color) of syntax highlighting. To determine the ID of the highlight group, hlID() can be used. See :help hlID():

:echo synIDattr(synIDtrans(hlID('StatusLine')), 'fg')

Upvotes: 16

Huluk
Huluk

Reputation: 874

You can get the background with

:echo &background

according to :help background there should be a foreground setting, too, but it doesn't work for me.

Edit: There are the variables guibg, guifg, ctermbg and ctermfg in :hi[glight]

Upvotes: 1

Related Questions