MPlak
MPlak

Reputation: 21

Vim syntax highlighting identifiers and functions in java

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.

Upvotes: 1

Views: 3620

Answers (2)

Tim
Tim

Reputation: 638

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.

Upvotes: 1

SteveW
SteveW

Reputation: 397

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).

Upvotes: 2

Related Questions