Sometimes when I create a new fold in vim, it folds the entire file. Why?
(foldmethod=manual)
e.g.,
zi(all folds are now open)zi(all folds are now closed)- lines 1-309 are folded closed, and lines 617-662 are folded closed (file has 662 lines)
- my cursor is on line 377
- I do
zfGto fold all lines from line 377 to end-of-file
Expected: lines 377 thru end-of-file are closed, and lines 310-366 are visible
Actual: all lines in file are closed
Workaround:
zD(delete all folds):1,309fold(fold 1-309):377,$fold(fold 377-eof)
My fold* settings:
foldclose=
foldcolumn=0
foldenable
foldexpr=0
foldignore=#
foldlevel=0
foldlevelstart=-1
foldmarker={{{,}}}
foldmethod=manual
foldminlines=1
foldnestmax=20
foldopen=block,hor,mark,percent,quickfix,tag,undo
foldtext=foldtext()
This is because line 377 (where I was creating a new fold) was within an existing open fold that started at line 1 of the file. So when I created the new fold, it increased the size of the existing open fold and closed it, causing the entire file to be folded closed.
To debug this,
:set foldcolumn=12shows open folds. AndzMcloses all open folds.Note also that I thought
zitoggled open/closed all folds, but that's not true.zMcloses all folds, andzRopens all folds.[I got the answer from this vi.stackexchange.com question]