VIM syntax folding : disable folding multi-line comments

I use the "syntax" foldmethod in vim 7.3. In .vimrc:

set foldmethod=syntax

When I open Test.cpp, containing:

/* A function with a multi-line
 * comment. This takes at least
 * four lines and I want to be
 * able to read all of them.
 */
void TheFunction()
{
  DoStuff();
}

I see the following when folded:

+--  5 lines: A function with a multi-line---------------------------------------------
void TheFunction() 
+--  3 lines: {------------------------------------------------------------------------

I like the function body folding, but not the comment-folding. I want to disable it so it looks like this:

/* A function with a multi-line
 * comment. This takes at least
 * four lines and I want to be
 * able to read all of them.
 */
void TheFunction() 
+--  3 lines: {------------------------------------------------------------------------

How do I do this? I can see the syntax group that's relevant with :syn list cComment

cComment       xxx matchgroup=cCommentStart start=+/\*+ end=+\*/+  extend fold contains
=@cCommentGroup,cCommentStartError,cSpaceError,@Spell
                   links to Comment

But tooling around for an hour with the vim documentation and google hasn't told me how to remove the "fold" attribute from this group.

Is my only recourse really to edit the language syntax file? I suppose it's less ugly to copy the system syntax file and use this, but I should be able to turn off a specific group with a command in my .vimrc.

Answers


When 'foldmethod' is set to "syntax" then /* */ comments and { } blocks will become a fold. If you don't want comments to become a fold use:

:let c_no_comment_fold = 1

Need Your Help

Array of references in Perl

arrays perl reference

I’ve read the reference documentation, but I can’t figure out how to dereference the array references inside my array.