1

I would like to highlight identifiers and functions for java while editing in vim.

For some reason when I try to set a hi for Function or Identifier in the vimrc nothing changes.

Any ideas? Thanks.

1

2 Answers 2

2

In looking at the java.vim file (/usr/share/vim/vim73/syntax/java.vim on my Mac), it appears that Identifier highlighting/syntax is not supported, and Function (declaration) highlighting requires that you set a flag in your .vimrc. So try something like this in your .vimrc file:

let java_highlight_functions = 1

Then there is some function highlighting, but it is not what I would hope for. It highlights the function return type, name, arguments, and braces. This is all I found without customizing the java.vim file (See C++ sample).

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

Comments

1

The regex which does the highlight can be customized to only highlight the identifier.

Here is my regex (just find this line in your java.vim syntax file and replace it with the below):

syn region javaFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(<[^>]*>\)\=\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*\ze(+ end=+\ze(+ contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses

It still doesn't work exactly right; see this question on Vim.SE for more detail.

Comments

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.