1

For some Markdown documents, I like them to open with some sections initially folded (I use the plugin vim-markdown-folding). I've tried setting a modeline that looks like this:

<!-- vi: set foldmethod=indent foldlevel=1: -->

This works, but unfortunately, every time I save the buffer, even with it still open, the folding is reset back to foldlevel 1. I'd really like it if the modeline only took effect when the file is first opened.

Is this possible?

  • 1
    does this happen with vim --clean? I wonder if there is some autocommand or something triggering this; nothing in the modeline help indicates this is default behavior – D. Ben Knoble May 21 at 21:35
  • 2
    Does it prevent Vim from re-reading the modeline if you use :noautocmd w to save? – filbranden May 22 at 1:55
  • 1
    Yes, @D.BenKnoble is right. It shouldn't be so. Try :au BufWrite to see if it's set up by some plugin or such. – Matt May 22 at 8:44
1

Thanks everyone for the helpful comments. I didn't realise that this was not default behaviour. But with some binary searching in disabling plugins, I was able to find out that this was due to my use of the vim-markdown-folding plugin (which in retrospect seems obvious, sorry). Its foldexpr overrides the one I was using and causes this issue. I may discontinue my use of the plugin or see if there is a way to use it which can be disabled for specific files.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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