Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 386
greduan Avatar asked Dec 26 '12 20:12

greduan


2 Answers

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')
like image 105
Ingo Karkat Avatar answered Nov 11 '22 23:11

Ingo Karkat


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]

like image 37
Huluk Avatar answered Nov 12 '22 00:11

Huluk