views:

107

answers:

1

Hi

How can I add new function names for .c and .h files to be highlighted, similar to this http://stackoverflow.com/questions/2464593/custumizing-syntax-highlighting-in-vim but much easier? (as I don't need to color words in different colors, only in the default color for keywords as defined by my theme).

I need this to add highlighting for function names in a project written in C which has a clearly defined API.

Thanks

+2  A: 

Try putting this in ~/.vim/after/syntax/c.vim:

syn keyword Keyword func_name1 func_name2 func_name3

you can see the defined highlight groups with:

:highlight

if you want to pick your colors:

syn keyword Myfunctions func_name1 func_name2
highlight Myfunctions guifg=red

assuming you use the GUI version and you like red, check :help highlight for details.

If you want to keep this particular highlight local to a project instead of applying it to every C file, you can add this to your .vimrc

au BufNewFile,BufRead *my_project/* source ~/.vim/myproject_syntax.vim

of course the path and the name and location of the syntax file are totally free.

kemp
You could also use an autocmd+function to apply them only to files within the path for that project, if it matters.
Jefromi
Er, or you could not get carried away, and just use an if within the ftplugin.
Jefromi
"an if" please elaborate on that
Flavius
What are other names like "Keyword" (capital K), and how to define my own color?
Flavius
Great. Someone said it's better to put it in `~/.vim/after/syntax/c.vim`. Please update your answer and I'll be glad to accept it. Thanks
Flavius