vim: enable folds but don't automatically close them

16

4

I really like the folding in Vim, but there are a couple non-file buffers (command-t plugin's window for one) that I really don't want it folding, as the normal fold commands don't work there.

If I could just tell vim to not automatically close folds (only close them when I tell it to) that should fix the problem, but I'm not seeing any options in the vim help for changing that behavior. Is there a way to have folding enabled but not automatically close all folds when a buffer is created/file opened?

Herms

Posted 2010-07-30T17:58:58.123

Reputation: 7 644

Answers

21

The command to have no folds closed when a buffer is opened is

:set foldlevelstart=99

See

:help foldlevelstart

for more.

garyjohn

Posted 2010-07-30T17:58:58.123

Reputation: 29 085

13

you can do:

set nofoldenable

for example in my .vimrc I have:

set foldmethod=indent       " automatically fold by indent level
set nofoldenable            " ... but have folds open by default

sml

Posted 2010-07-30T17:58:58.123

Reputation: 1 582

2

From http://tech.groups.yahoo.com/group/vim/message/119298: "With nofoldenable, all folds are open, as if they did not exist at all. You cannot interact with them. But, as soon as you try interacting with them (by pressing zc for example) you automatically set foldenable, which will apply all the folds that exist in the window."

– Mansoor Siddiqui – 2011-08-06T18:35:41.233

0

zR is the command to open all folds. I assume you could use vim's autocommand (au) to just put an option in your .vimrc to issue the command zR when opening a buffer with the file extensions you don't want started up with automatic closing of folds. Something like this:

au BufRead *.myext zR

haven't tested, actually correct syntax may be use exe command for the zR:

au BufRead *.myext exe "zR"

I'm assuming you're talking about autofolding of manually-defined or automatically defined folds when a buffer is opened. If the buffers in questions are not supposed to have folds at all, then it's probably a different issue, something where you want to have folding disabled for those buffer types.

Herbert Sitz

Posted 2010-07-30T17:58:58.123

Reputation: 336

yea, but zR doesn't work when I'm in the buffer, so I'm not sure if the automatic command would work. – Herms – 2010-07-30T20:17:35.820