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

2

10

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!

Ishii answered 26/12, 2012 at 20:19 Comment(0)
R
16

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')
Ryurik answered 27/12, 2012 at 0:42 Comment(0)
A
1

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]

Annia answered 26/12, 2012 at 20:26 Comment(8)
Oh no, I don't mean the option to use either a dark/light background. But rather a way to know what color the theme was using. For example how to know the exact color the theme is using for comments for example.Ishii
Oh I read the documentation you pointed to and I think that might be it, however I'm not sure.Ishii
It might be possible using the &fg and &bg, however I need to run some tests to make sure. If you find out definitely be sure to tell me about it. :)Ishii
Hmm nope, seems that isn't it. Never the less a +1. :)Ishii
Maybe you are looking for ctermbg and ctermfg in :hiAnnia
Yes that's right! I'm gonna edit the question. Also for guifg and guibg as well (I can't remember if it's called exactly that).Ishii
it is, just found it and wanted to add :)Annia
I did find something, I put it in my main post.Ishii

© 2022 - 2024 — McMap. All rights reserved.