1

How can I add new function names for .c and .h files to be highlighted, similar to this Customizing 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

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

You could also use an autocmd+function to apply them only to files within the path for that project, if it matters.
Er, or you could not get carried away, and just use an if within the ftplugin.
"an if" please elaborate on that
What are other names like "Keyword" (capital K), and how to define my own color?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.