2

Vim has a handy feature in :syntax sync fromstart which allows me to fix syntax highlighting when it gets confused during an extended editing session. I map it to <leader>ss (reSync from Start) because I use it so often.

How would I achieve the same effect with code folding that uses a fold expression? From time-to-time, especially when commenting out areas of code, the folds will get out of sync with the actual buffer contents, and I'd be more than happy to wait the fraction of a second it would take Vim to recalculate the folds from scratch.

I'm happy for a short script if that's what it would take. I'm developing my vimscript-fu and would be happy for the exercise :)

4

It sounds like you're looking for zx or zX.

From the Vim documentation on fold,

zx
Update folds: Undo manually opened and closed folds: re-apply 'foldlevel', then do "zv": View cursor line. Also forces recomputing folds. This is useful when using 'foldexpr' and the buffer is changed in a way that results in folds not to be updated properly.

zX
Undo manually opened and closed folds: re-apply 'foldlevel'. Also forces recomputing folds, like |zx|.

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.