History
Article Edit this page Discussion

Fold braces and javadoc

From Vim Tips Wiki

Jump to: navigation, search

[edit] Duplicate tip

This tip is very similar to the following:

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

Tip 304 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

[edit] Comments

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.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Fold braces and javadoc"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation