Question

I'm coding C# in Vim and I want to be able to fold both

+---- 3 lines: void SomeFunction()-----------------------------------------------

As well as

+---- 42 lines: #region The Answer To Life---------------------------------------

However, foldmarker must be a literal string. I've been led to the idea of foldmethod=syntax, but this doesn't work out of the box in Vim 7.3.

Other than setting the fold method to manual and writing a script, how can I achieve this?

Was it helpful?

Solution

My Vim 7.3 runtime has a syntax/cs.vim file (from 14-Aug-2009) that supports syntax folding for #region. Syntax folding is nice; I'd advise against another foldmethod. I would contact the author of the syntax file and suggest the missing folding of functions as an enhancement; many other filetypes have this, and it seems to be common and helpful. (This can be made configurable for those who don't want one or the other.)

In the meantime, you can add the following to ~/.vim/after/syntax/cs.vim to enable folding of any curly braces blocks:

syn region csFold start="{" end="}" transparent fold
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top