tags:

views:

82

answers:

3

I noticed that when I create a new fold (I'm using foldmethod=marker) all the folds below the one I'm creating are automatically opened, is there a way to prevent this and leave them closed?

I can't use zf to manually create a fold because I'm editing PHP/HTML and there is no 'commentstring' format good for both.

+1  A: 

Try creating the end marker ("}}}") before creating the start marker ("{{{"). This should prevent vim from getting confused and opening the following folds.

Also, if you find you've accidentally opened some folds, just re-edit the file (":e") to reset them.

Lucas Oman
+1 since this works, although it's not ideal
kemp
A: 

Rather than typing out the marks by hand, I tend to visually mark the reigon I want to fold with V then use zf to create the fold.

This does not open any folds that aren't open already.

Randy Morris
This would be good but I need to fold both PHP and HTML code, so I can't have a single `'commentstring'`
kemp
Might want to edit your question to include that information so people don't have to read all the comments to find it.
Randy Morris
+2  A: 

It's possible not only by creating closing marker before opening one, but also by specifying fold level in markers.

/*{{{1*/
    // Fold you are closing.
    // Inserting this closing marker below would not cause opening next fold.
/*}}}*/

/*{{{1*/
    // Closed fold.
/*}}}*/

In this case fold's level helps Vim to find matching closing marker and not to try one that closes next fold.

ib
Seems to make no difference, as soon as I insert the closing marker, all other folds below are open
kemp
Are levels specified for those folds (next to one you are closing) too?
ib
Good point, no they aren't
kemp
That's why Vim still tries to open them to find matching markers. Appending level numbers to the markers solves the problem.
ib