How to color specified text in vim?

editor, vim

Solution

to extend C/CPP syntax (and that can apply to any language, just check for the already existing names, like `Constant` here) :

in your `~/.vimrc`

if has("autocmd")
    augroup filetypedetect
            au BufNewFile,BufRead *.myext    setf mysyntax
    augroup END
endif

and in your `~/.vim/syntax/mysyntax.vim`

runtime! syntax/cpp.vim

syn keyword myConstant foo bar foobar quack
hi def link myConstant Constant

to create new keywords from scratch :

syn match myKeyWord "foobar" contained
hi kwRed  term=standout ctermfg=12 guifg=Red
hi def link  myKeyWord  kwRed

and you can call that with `filetypedetect`, or directly in your `.vimrc`

Problem

Whenever I'm typing programming keywords in vim they get specific colors. I'd like to create my own. How can I color text with specified color? I tried to find the answer but haven't found it yet

Original source