Stopping VIM from opening all subsequent closed folds when creating a new one

StackOverflow https://stackoverflow.com/questions/2140103

  •  22-09-2019
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top