In my config file I have set foldclose=all so that folds get automatically closed upon cursor leaving them. However, sometimes, I want a specific fold not to close for a while.

Because folds below foldlevel=# and folds smaller than foldminlines=# are not affected by foldclose=all, there must exist a list of folds that foldclose=all doesn't work on.

I want to create a mapping that puts a particular fold (the one where my cursor is) to that list so that it's temporarily not affected by foldclose=all, i.e., so that it doesn't close automatically even though foldclose is set to all.

How can I add folds to those that foldclose=all doesn't work on?

I did not find anything in the neovim documentation on folds and tried to make a workaround by using :mkview but then I would have to have :loadview triggered every time a fold is closed, which I don't know how to do (and doesn't seem to be feasible and efficient). I work in c++ and my default settings are foldlevel=1, foldmethod=syntax, foldopen=hor.

  • :help 'foldclose' says When set to "all", a fold is closed when the cursor isn't in it and its level is higher than 'foldlevel'. Useful if you want folds to automatically close when moving out of them. So you would need a fold with level smaller than foldlevel to not be affected by foldclose=all.
    – D. Ben Knoble
    Commented Jul 10, 2022 at 18:18
  • Folds smaller than Foldminlines are also not affected. The answer is not in documentation, I am quite sure. I was hoping for an expert to tell me how to utilize neovim source code. Folds below specified level are excepted from foldclose so I want to add new folds to that exception list.
    – lobelk
    Commented Jul 11, 2022 at 3:48

1 Answer 1


Vim defaults to foldlevel=0. Consider setting it in vimrc to 2 and setting the fold you want left open to 1.

I use fold markers, and the way to set fold levels is to add a number to the marker:

" I'm fold 1 {{{1
" End fold 1 }}}

" I'm fold 2 {{{2
" End fold 2 }}}

If you're using some other fold method, I'm not sure how to set the level of a particular fold. I can't seem to locate that information in the docs.

An alternative, if you truly do want it open permanently as the title of your question says, is to delete the fold.

  • 1
    Note that folds also get a level via "nesting", so a fold inside a fold with level N has level N+1.
    – D. Ben Knoble
    Commented Jul 10, 2022 at 18:17
  • @D.BenKnoble Really? I've never seemed to be able to get that to work, but it's been a while. I'll have to try it again. Then again, I like explicitness.
    – MDeBusk
    Commented Jul 10, 2022 at 23:31
  • 1
    I spoke without checking the docs, but I’m fairly certain that’s correct.
    – D. Ben Knoble
    Commented Jul 10, 2022 at 23:34

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.