I'm using neovim v0.4.4, vim-plug, and uiiaoo/java-syntax.vim.

For some unknown reason(s), syntax highlighting from java-syntax only works on the 1st java buffer. For example:

$ nvim file1.java
:e file2.java
$ nvim notJava.txt
:vs file1.java
:sp file2.java

In both cases, only file1.java has syntax highlighting from java-syntax, while file2 doesn't.

My init.vim

filetype on
filetype plugin on
syntax on

" In vim-plug
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    Plug 'uiiaoo/java-syntax.vim', {'for': 'java'}

" For coc.nvim
let g:coc_global_extensions = [
    \ 'coc-java',
    \ 'coc-highlight',

I don't see anything here that would interfere with java-syntax. What might be the cause for only the first Java buffer getting the syntax highlighting?

  • 1
    If java-syntax is setup correctly, the for clause should be unnecessary. Filetype plugins and syntaxes already only load when needed, so you’re not usually saving anything extra there. I wonder if somehow that’s what’s getting in the way?
    – D. Ben Knoble
    Nov 16, 2020 at 14:14
  • @D.BenKnoble I added the for just in case. The problem was there before adding for. Nov 16, 2020 at 15:14
  • Does :set ft? tell you filetype=java in both file1.java and file2.java?
    – filbranden
    Nov 16, 2020 at 17:22
  • 2
    @JohnZhau This line in java-syntax.vim looks odd: let b:current_syntax = "java-syntax.vim". I believe it should set it to "java", which matches the file type... I haven't had time to check whether this can be what causes the issue you're having, but that's where I would have started...
    – filbranden
    Nov 17, 2020 at 17:56
  • 1
    I've found that disabling sheerun/vim-polyglot solved the issue. I'll update & answer with furthur details after I've got polyglot to work with java-syntax. Nov 19, 2020 at 6:53

1 Answer 1


I've found that disabling sheerun/vim-polyglot solved the problem. I'm not sure why exactly polyglot was causing it, but seeing as Java isn't supported by polyglot, I disabled it by putting the following line before polyglot is loaded.

let g:polyglot_disabled = ['java']

For reference, here's my plugin portion (I'm using vim-plug)

call plug#begin('$HOME/.config/nvim/plugged')
   " Some other plugins
    let g:polyglot_disabled = ['java']
    Plug 'sheerun/vim-polyglot'
call plug#end()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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