Better syntax highlighting for Java in Vim

javasublime-text-2syntax highlightingvim

I've found Vim to have fantastic syntax highlighting with my preferred color schemes for Ruby and Python, but whenever I need to write Java code, it's like I haven't even turned on highlighting in the first place.

As you can see, keywords are highlighted, but there's no highlighting for parentheses or methods. In Sublime Text (a far less preferred editor by me), I see far better highlighting. There is italicization for class names and highlighting for mathematical operators. Vim looks sparse in comparison.

Is there any way, any way at all to get that luscious Sublime Text-style highlighting on Vim?

Best Answer

Have a look at the cSyntaxAfter plugin. It highlights operators et cetera.

Another option is to edit the syntax/java.vim script and add highlighting for the Operator group. Have a look at syntax/pascal.vim as an example.

It you want to use italics for class names, that should be possible if the java syntax file recognizes them as a group, and I think it does. It seems that class names are in the JavaTypedef group.

You would then have to define a new highlight for that group. That would mean removing the line

JavaHiLink javaTypedef                Typedef

from the syntax file, and adding a new one. Below I'm re-using the hightlight declaration for Type, which is what Typedef is linked to. I changed the term from underline to italic.

You should put the following in yout java.vim syntax file.

hi javaTypedef term=italic cterm=NONE ctermfg=LightGreen ctermbg=NONE gui=bold guifg=#60ff60 guibg=NONE
Related Question