Search code examples
vimsyntax-highlightingvim-syntax-highlighting

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?


Solution

  • @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')