Vim Tips Wiki
Advertisement
Tip 143 Printable Monobook Previous Next

created October 20, 2001 · complexity basic · author Sameer Chabungbam · version 6.0


The fold-method marker can be effectively use to set the folds in your Java source. Define some marker and place it inside HTML comments . This way, it does not affect the Javadocs generated without the necessity of a seprate comment line.

For example:

/**
 * <!-- zz.FOLDSTART class AbcClass -->
 * The class description.
 * ...
 */
public class AbcClass {
 /**
 * <!-- method zz.FOLDSTART someMethod() -->
 * Method description.
 */
 public void someMethod();
 ...
} /* zz.END: AbcClass */

/* Put this at the end of your file */
/* vim:fdm=marker fmr=zz.FOLDSTART,zz.END fdl=2 fdc=2: */

Now, the files will be opened with the methods neatly folded.

You can use "zR" to open all folds (or click on the "+" at the left column).

Comments

Another thing you might try, if you don't feel like mucking up your code by adding markers everywhere(I really love folding but I don't like the idea of having to modify my sources to get it to work just right) is to set your foldmarker to the javadoc comment blocks:

fdm=/**,*/

Seems to work pretty well, doesn't interfere with normal /* */ chunks anyway.


Really nice folding on /* */ if you are editing source that's overcommented.

I use these settings to autoload java files:

autocmd FileType java :set fmr=/**,*/ fdm=marker fdc=1

It seems like the last idea is a bit buggy. Not all javadoc comments fold automatically, and some really weird behavior results. But the following works like a charm:

In java.vim, change the javaDocComment line to:

syn region javaDocComment start="/\*\*" end="\*/" transparent fold keepend contains=javaCommentTitle,@javaHtml,javaDocTags,javaTodo,@Spell

(added "transparent fold").

Then in my .vimrc I added: set foldmethod=syntax

No more annoying javadoc comments everywhere.


Oops, you probably want to leave the "transparent" out...it changes your javadoc colors to white! I misunderstood the very :help :syn-fold.


Advertisement