I use foldmethod=indentbut I hate how it starts each file pre-folded. To get around this I put au BufWinEnter * normal zi in my vimrc. That had worked fine so far, but now that I started using CoC, My error messages are getting auto-folded, which is obviously not what I want. I tried adding MenuPopup to the autocommand but no luck. How can I get this... window? (Idk what it is as far as Vim is concerned) to no automatically fold its text?

enter image description here


2 Answers 2


Put set nofoldenable in your vimrc. This will also accomplish what your autocommand does.

  • 1
    This does indeed keep everything unfolded initially, but as soon as you toggle on one fold, that changes the value of nofoldenable and the entire file gets folded again. That might be sufficient for certain use cases but not others. Commented Oct 2, 2023 at 17:50

Although this is probably the best place for this question, it has also been asked on other more popular sites:

Answers generally fall into three categories.

The first is what has already been posted here, which is to set nofoldenable. This on first glance appears to be correct, but it's an internal variable modified by the various fold commands. The consequence of this is that as soon as you execute a fold command (for instance, za), nofoldenable is overwritten and all folds are collapsed. This is probably not what you want.

The second is to use BufRead or similar to execute a folding command once you open a buffer. This will work, but to my mind is more of a hack than option three.

Option three then being to utilize foldlevelstart. Foldlevel is a variable that

Sets the fold level: Folds with a higher level will be closed. Setting this option to zero will close all folds. Higher numbers will close fewer folds. This option is set by commands like zm, zM and zR.

(Note that it isn't modified by smaller-scoped fold commands like za, like nofoldenable is.)

foldlevelstart then sets foldlevel when opening a buffer:

Sets 'foldlevel' when starting to edit another buffer in a window. Useful to always start editing with all folds closed (value zero), some folds closed (one) or no folds closed (99).

This is all to say that you can use a snippet like this in your vimrc:

" Enable folding, but don't collapse folds by default.
set foldmethod=indent
set foldlevelstart=99

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.