Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to partially "link" highlighting groups?

I'm trying to do this on my .vimrc:

hi link SyntasticErrorLine SignColumn
hi link SyntasticErrorSign SignColumn
hi SyntasticErrorSign guifg=red ctermfg=red

What I want is to have the SyntasticErrorSign highlighting group with the same background as SignColumn but with custom foreground colors.

Vim docs says:

- As soon as you use a ":highlight" command for a linked group, the link is removed.

So, the way I'm doing it won't work anyway, is there a way to achieve that?

like image 995
pepper_chico Avatar asked Sep 12 '13 21:09

pepper_chico


2 Answers

@Kent answer was good, but it seems there's a problem with synIDattr when one doesn't pass the mode argument, it fails to return the attribute in GUI mode (gvim). I've learned this from vim-arline plugin sources.

I've solved my problem with:

hi link SyntasticErrorLine SignColumn

exec 'hi SyntasticErrorSign guifg=red ctermfg=red' .
            \' guibg=' . synIDattr(synIDtrans(hlID('SignColumn')), 'bg', 'gui') .
            \' ctermbg=' . synIDattr(synIDtrans(hlID('SignColumn')), 'bg', 'cterm')
like image 194
pepper_chico Avatar answered Sep 22 '22 22:09

pepper_chico


If you want to "steal" some hl-attribute value from other group, you don't have to link, you just get the value for your own usage.

For your problem, try to add this line into your .vimrc file.

exec 'hi SyntasticErrorSign guifg=red ctermfg=red ' . (has("gui_running")? 'guibg=':'ctermbg=') . synIDattr(hlID('SignColumn'),'bg')

The line sets fg(gui and cterm) of SyntasticErrorSign group as red, and uses the same bg color of group SignColumn, depends on you are in gvim or vim. I think it should be what you are looking for.

For those functions, you could just :h xxx() to get detailed information.

like image 30
Kent Avatar answered Sep 21 '22 22:09

Kent