vimtricks.wiki Concise Vim tricks, one at a time.

How do I create custom highlight groups and override colorscheme colors?

Answer

:highlight MyGroup guifg=#ff0000 guibg=NONE gui=bold

Explanation

The :highlight command lets you define custom colors for syntax elements, UI components, and your own highlight groups. This is how you customize your editor's appearance beyond what colorschemes provide.

How it works

  • :highlight {Group} {key}={value} — set highlight attributes
  • guifg / guibg — foreground/background for GUI and terminal with termguicolors
  • ctermfg / ctermbg — foreground/background for 256-color terminals
  • gui / cterm — attributes: bold, italic, underline, reverse, NONE

Example

" Custom highlight group
highlight MyGroup guifg=#ff0000 guibg=NONE gui=bold

" Override an existing group
highlight Comment guifg=#888888 gui=italic

" Link one group to another
highlight! link MyGroup ErrorMsg

" Clear a group
highlight clear MyGroup

Tips

  • Place overrides in after/plugin/colors.vim so they load after colorschemes
  • Use autocmd ColorScheme * highlight ... to preserve overrides when switching schemes
  • :highlight (no args) lists all active highlight groups
  • :so $VIMRUNTIME/syntax/hitest.vim shows all groups with their colors

Next

How do I return to normal mode from absolutely any mode in Vim?