Stopping VIM from opening all subsequent closed folds when creating a new one
Question
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.
Solution
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.
OTHER TIPS
It is possible not only by creating the closing marker before the opening one, but also by specifying the fold level in markers.
{{{1
Fold you are closing.
Inserting the closing marker below would not open the next fold.
}}}
{{{1
Closed fold.
}}}
In this case fold level helps Vim to find matching closing marker and not to try one that closes the next fold.
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.