According to the documentation, the only command that recompute folds is the zx command. However, the problem is that zx automatically undoes all manually opened or closed folds. If I have a bunch of folded text prior to running zx, all of those text would be unfolded (and the folds disappear) after I run zx.

My current solution is to define an autocommand to run set foldmethod=expr at every InsertLeave and TextChange event. However, I can't help but find this solution a bit 'hackish' and inelegant.

If anyone knows a better way, please point me in the right direction.

  • Folds should be automatically recomputed in many cases… you should only rarely if ever need commands like zx.
    – D. Ben Knoble
    Mar 1 at 14:34


Your Answer

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

Browse other questions tagged or ask your own question.