Wikia

Vim Tips Wiki

Watchlist Recent changes

Fold braces and javadoc

Redirected from VimTip304

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

This tip is deprecated for the following reasons:

The functionality described in this Tip has been mostly replaced with syntax folding in version 7. Nevertheless, the default Java syntax file still only includes braces.

Tip 304 Printable Monobook Previous Next

created August 10, 2002 · complexity intermediate · author Daniel Bauke · version 6.0


If you'd like to have javadoc folded together with areas in braces try that

set foldmethod=syntax
set foldenable
syn region foldBraces start=/{/ end=/}/ transparent fold
syn region foldJavadoc start=,/\*\*, end=,\*/, transparent fold keepend

and play a bit with:

set foldlevel=0
set foldnestmax=10

parameters

CommentsEdit

This is great, but I had a lot of problems with it (brace-folds kept folding to the end of the class etc). It seems that my settings for java highlighting (e.g. let java_highlight_functions="style") have a lot to do with it. So I did some changes.

I cannot really explain exactly why the following works, but it does for me:

 syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
 syn region foldJavadoc start=+/\*+ end=+\*/+ transparent fold keepend extend
This works (for braces) because the "keepend" makes sure that any contained items end whenever the braces region ends, whether or not the contained item already ended. The "extend" allows THIS GROUP to override the keepend setting for a container group, so that you can nest this group. For this reason, I doubt very much that you really want to add "extend" to the foldJavadoc group. If you do, javadoc comments become nestable for folding!

I also added folding for import statements. This could probably be a lot cleaner; still, here goes:

syn keyword javaExternal native package
syn region foldImports start=/\(^\s*\n^import\)\@<= .\+;/ end=+^\s*$+ transparent fold keepend

Notably the \n in the start of foldImports and the redefinition of javaExternal (so that import will match) seem quite nasty. If you have a better solution for this, please share them here.


Pages on Vim Tips Wiki

Add a Page
1,601pages on
this wiki

Latest Photos

Add a Photo
66photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki