Robert Speicher
Robert Speicher

Reputation: 15562

The first time I close a fold, it closes all folds

I have the following in my vimrc:

set foldmethod=syntax
set foldnestmax=3
set nofoldenable

When I open a file, nothing is folded, as expected. The first time I close a fold using zc, it closes all possible folds recursively. Then I issue zR and it reveals them all, and then zc behaves as expected, closing one fold at a time. It appears that za behaves the same way; the first time it folds everything, every time after that it folds one thing.

Is there a way to make zc always close a single fold? I'm basically trying to eliminate the "close everything, and then reveal everything" step that I have to do any time I want to fold something.

Upvotes: 11

Views: 1787

Answers (1)

Jan Larres
Jan Larres

Reputation: 903

What happens is that pressing zc will turn on folding (see :help zc), and this will make Vim apply 'foldlevel' which is 0 by default (meaning all folds will be closed). So if you set 'foldlevel' to a high value in your vimrc it should work as expected.

Upvotes: 17

Related Questions