Question

I was attempting to do some programming from a machine at work and I am unable to get Vim to recognize folds in my Java program. I've set the foldmethod to "syntax", but I get: "No Fold Found" when I try to collapse method bodies. I changed the filetype to "cpp" to test foldmethod=syntax and it worked!

I attempted to compare 'java.vim' and 'cpp.vim' to see if I could discern the problem, but I could not make out an issue with 'java.vim'.

My 'java.vim' has the following header:

" Vim syntax file                                                                                                                                                                                   
" Language:     Java                                                                                                                                                                                
" Maintainer:   Claudio Fleiner <claudio@fleiner.com>                                                                                                                                               
" URL:      http://www.fleiner.com/vim/syntax/java.vim                                                                                                                                              
" Last Change:  2007 Dec 21  

Does anyone have any ideas?

Was it helpful?

Solution

Which Vim version?

The default Vim 7.3.000 install ships syntax/java.vim with a version of 2010 March 23; the latest runtime files (from Mercurial repo) have 2012 Oct 05; both can do Java folding. I strongly recommend you to upgrade.

If you cannot do this, put the following into ~/.vim/after/syntax/java.vim:

if v:version < 703
    " The default Java syntax file lacks the 'fold' option.
    syn region javaFold start="{" end="}" transparent fold
endif
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top