Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to color specified text in vim?

Tags:

vim

editor

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

like image 718
sat Avatar asked May 21 '12 14:05

sat


2 Answers

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

like image 59
zmo Avatar answered Oct 04 '22 18:10

zmo


To extend a particular filetype syntax (like e.g. Java's), use :syntax and :highlight. If you just want to color particular words in a window, you can quickly use :match, or any of the available "multiple markers" plugins like mark.vim.

like image 28
Ingo Karkat Avatar answered Oct 04 '22 18:10

Ingo Karkat