I am going through the unfortunate process of making keybinds to change colorschemes, but different plugins have their own highlight groups which is making this difficult.

Is there a way to set the terminal background color for all highlight groups of a specific color at the same time? I am trying to make all the white background components grey (color 254).

2 Answers 2


You can probably loop the list returned by getcompletion('','highlight') and get the background with synIDattr(synIDtrans(hlID(l:thislistitem)), "bg") (see :h hlID()).


As Bart mentioned, you can set all highlight groups with getcompletion('', 'highlight'):

for l:highlightGroup in getcompletion('', 'highlight')
  execute "hi " . l:highlightGroup . " ctermfg=7 ctermbg=none guifg=White guibg=none"

This will overwrite the link from each highlight group to the other though. I didn't like that since I wanted to create a color scheme by starting from a clean state with links intact. This way, I only have to define custom colors for a few "root" highlight groups and not all of their descendants.

The following only changes root highlight groups, i.e., groups that link to themselves:

for l:highlightGroup in getcompletion('', 'highlight')

  " Get the group this highlight group links to
  let l:linkedGroup = GetLinkTarget(l:highlightGroup)
  " Only set the root highlight groups (those that don't link to others).
  " This leaves links intact
  if l:highlightGroup ==# l:linkedGroup
    execute "hi " . l:highlightGroup . " ctermfg=7 ctermbg=none guifg=White guibg=none"

function! GetLinkTarget(group)
    let l:groupID = hlID(a:group)
    " Get the group this highlight group links to
    let l:linkedGroupID = synIDtrans(l:groupID)
    let l:linkedGroupName = synIDattr(l:linkedGroupID, 'name')
    return l:linkedGroupName

As an alternative to getcompletion('', 'highlight'), you can parse syntax list which shows all highlight groups, where they link to, and when they're applied.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.