Let's assume we want to create a custom colorscheme. For example, content of a custom colorscheme file ~/.vim/colors/mytheme.vim are as follows,

" syntax highlighting groups
hi Comment  guifg=#007f7f
hi Constant guifg=#ffa0a0

As you can see in above code snippet, I am just defining colors for default highlight groups.

  1. How can add extend default highlight group? i.e. I want to add some words to be considered under Comment group.
  2. How to create new highlight group e.g. StylishComments? And similarly add few words under that group?
  • 1
    A colorsheme file defines colors for groups. A syntax file defines what elements the groups consist of. These are two different things.
    – Matt
    Commented Oct 31, 2019 at 18:08

1 Answer 1


In general, you can't/shouldn't "create a custom colorscheme in which define custom highlight group each of containing set of words".

What you can/should do:

  1. define your colorscheme file where for the color groups specific colors are defined (example snip):
set background=dark

hi clear
if exists('syntax_on')
    syntax reset

let g:colors_name = 'mycolorscheme'

hi Comment  guifg=#007f7f
hi Constant guifg=#ffa0a0
"... other color groups if needed. Otherwise default values would be used.
  1. define syntax file that create syntax elements such as comments, keywords, constants, etc and maps them to colorgroups (existing or created by you), for example for asciidoctor syntax I have:
if exists("b:current_syntax")

syn match asciidoctorComment "^//.*$"

hi def link asciidoctorComment               Comment
" ... other syntax elements

Where I define what is asciidoctor comment -- something that start with double slash in the beginning of the line till the end of the line -- and map it to default Comment highlight group.

And to be closer to your questions:

  1. you can try to do explicit:
syntax match Comment "hello\|world"

That would make words "hello" and "world" a comment, kind of. Although it would be overwritten when you open a new file with defined syntax, so you should have find a way to properly execute this after current syntax file was loaded. (:h autocommand)

  1. Well it is the same, but you have to add highlight for that group:
syntax match StylishComments "My\|Stylish\|Comments"
hi StylishComments guifg="#ffff00"

Here is the same issue as with pt.1 but it also will probably overwritten after you change colorscheme.

You can try it in vim session :syntax ... to see if it works for you (it worked for me:). Then decide what route to go, either using autocommands in vimrc to reapply those commands after filetype and/or colorscheme was changed or create a proper syntax and colorscheme files.

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.