22

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?

3 Answers 3

26

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

:set foldlevelstart=99

See

:help foldlevelstart

for more.

0
14

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
2
  • 6
    From 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." Aug 6, 2011 at 18:35
  • 2
    To clarify @MansoorSiddiqui's comment, this is probably not the setting you're looking for. Jul 23, 2021 at 18:42
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.

2
  • yea, but zR doesn't work when I'm in the buffer, so I'm not sure if the automatic command would work.
    – Herms
    Jul 30, 2010 at 20:17
  • @Herms I know you asked over ten years ago, but I'm not sure why zR wouldn't work when you're in a buffer. That's the only time it should work. Jul 23, 2021 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .