Better syntax highlighting for Java in Vim?
Solution 1:
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
Solution 2:
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!
Solution 3:
I'm using base16-default color scheme in Vim and for some reason it does a bad job defining colors for Java. Adding the following lines will help get part of the way there:
" Java: 'new', 'instanceof'
highlight Operator ctermfg=5 guifg=#d175bc
" Java: 'this', 'super'
highlight Typedef ctermfg=5 guifg=#d175bc
" Java: 'void', 'int', 'double'
highlight Type ctermfg=4 guifg=#69b7d3
" literal numbers
highlight Number term=bold ctermfg=16 gui=bold guifg=#d2d22d