Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Have you tried using Vintage mode in Sublime Text? It changes all the key bindings to those vi(m) uses, yet still allows for powerful features of ST2 like better syntax highlighting and multiple selection editing. – MattDMo Aug 3 '13 at 23:36
I do have Vintage Mode enabled in ST2, but I still prefer Vim because I can use it in the terminal, with several tmux panes open so that I can ssh into my remote machine simultaneously without leaving my editor for more than a second. – kunaicode Aug 3 '13 at 23:46
yes, there is that minor setback of using a GUI editor... – MattDMo Aug 3 '13 at 23:50
up vote 0 down vote accepted

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
share|improve this answer
Thanks for the help, but is/are there any plugin or plugins to capitalize class names? – kunaicode Aug 19 '13 at 0:43
@kunaicode: Not that I know of. Syntax highlighting doesn't alter the meaning of the code. Capitalization does. Personally I'd immediately remove a plugin that would automatically change code that I have written. – Roland Smith Aug 19 '13 at 17:11
I apologize for the confusion-- I meant, italicize class names. Not capitalize. Sorry. – kunaicode Aug 21 '13 at 23:46
@kunaicode: See updated answer. – Roland Smith Aug 24 '13 at 10:27

Here is my attempt at best vi Java highlighting:

Notice Integer and System are pretty blue instead of white. Humans are primarally visual and color-based thinkers. This helps the brain quickly ascertain what the code is doing and speeds understanding which speeds coding time.

Java syntax highlighting and colors for vim

You will need to copy some files into your /home/yourusername/.vim/colors and /home/yourusername/.vim/syntax folders. Then configure some commands in your /home/yourusername/.vimrc and you should get what I get.

share|improve this answer

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.