How to color the specified text in vim?

Whenever I type programming keywords in vim, they get certain colors.

I would like to create my own.

How is the color of the text with the specified color?

I tried to find the answer, but have not found it yet

+4
source share
3 answers

to extend the C / CPP syntax (and which can be applied to any language, just check existing names like Constant ):

in ~/.vimrc

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

and in ~/.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 it with filetypedetect or directly in .vimrc

+4
source

To extend the specific file type syntax (e.g. Java), use :syntax and :highlight . If you just want to highlight individual words in a window, you can quickly use :match or any of the available plugins with several markers, for example mark.vim .

+2
source

Look match

 :match Identifier /\w\+/ :2match Keyword /\v(if|else|then|break)/ 

See also :hi to view highlight groups. Alternatively, you can write a syntax file that is / way / more involved

+2
source

Source: https://habr.com/ru/post/1413531/


All Articles