5

I recently found this little piece of code for my .vimrc

if has("autocmd")
  " Highlight TODO, FIXME, NOTE, etc.
  if v:version > 701
    autocmd Syntax * call matchadd('Todo',  '\W\zs\(TODO\|FIXME\|CHANGED\|XXX\|BUG\|HACK\)')
    autocmd Syntax * call matchadd('Debug', '\W\zs\(NOTE\|INFO\|IDEA\)')
  endif
endif

Basically, it allows me to define keywords which are matched with different highlighting (Todo and Debug are the names of the colors).

Is there a way that I can define my own coloring schemes and give them names? Specifically what I want to have is 3 tags: TODO1, TODO2 and TODO3. The idea is that TODO3 is lower priority than TODO1 and thus is highlighted in a lighter shade.

If I can't define my own coloring, where can I find a list of the color names I can use?

Community
  • 1
  • 1
David Tuite
  • 22,258
  • 25
  • 106
  • 176
  • I answered a similar question that might be able to help you out. It basically tells you how to define your own matching colors (on top of whatever colorscheme you are using): http://stackoverflow.com/questions/6386085/vim-syntax-highlighting/6388100#6388100 – alfredodeza Aug 04 '11 at 14:00

1 Answers1

3

If you don't want to use default theme colors, here is the solution:

" Define autocmd for some highlighting *before* the colorscheme is loaded
augroup VimrcColors
au!
  autocmd ColorScheme * highlight ExtraWhitespace ctermbg=darkgreen guibg=#444444
  autocmd ColorScheme * highlight Tab             ctermbg=darkblue  guibg=darkblue
augroup END

And later on (this must be after):

" Load color scheme
colorscheme yourscheme

Color definitions follow the format:

autocmd ColorScheme * highlight <ColorName> ctermbg=<TerminalBackgroundColour> guibg=<GuiBackgroundColour> ctermfg=<TerminalFontColor> guifg=<GuiFontColour>

Where the cterm colors must come from a predefined list (see :help cterm-colors for more info). Gui colors can be any Hex color.

Plouff
  • 3,290
  • 2
  • 27
  • 45
  • 2
    Your `if !exists('var') | let var=1 | ... | endif` is naturally expressed by `augroup vimrcColors | autocmd! | ... | augroup END`. It has an advantage of you not being forced to unlet a variable and delete autocommands manually in order to reload them. – ZyX Sep 07 '11 at 19:41
  • Thanks for the advice. I have seen it one day, but I did not get the advantage. I am going to give it a try! – Plouff Sep 08 '11 at 07:15
  • @Plouff, Thanks a million for your answer. Perhaps you might edit with ZyX's suggestion? I don't really understand what he means. – David Tuite Sep 15 '11 at 12:04
  • Hi, glad it helped! I updated the solution with the comment of ZyX. The code is must more clean in this way. Thanks again – Plouff Sep 15 '11 at 15:24
  • I updated the solution one more time since I forgot to remove the variable assignment... This should be the final answer. – Plouff Sep 16 '11 at 07:23