Better syntax highlighting for Java in Vim?
It seems there simply isn't a rich syntax file out there.
But we can squeeze a little bit more out of the bundled syntax file we have:
let java_highlight_functions = 1
let java_highlight_all = 1
" If you are trying this at runtime, you need to reload the syntax file
set filetype=java
" Some more highlights, in addition to those suggested by cmcginty
highlight link javaScopeDecl Statement
highlight link javaType Type
highlight link javaDocTags PreProc
The first trick came from here.
If someone ever makes a richer Java syntax file, we should add it to vim-polyglot!
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