I have some configuration in my .vimrc governing the initial folding strategy. Sometimes, I am looking to restore the initial state and would like a :refold command or something, which restores the initial state.

Is there some built-in way to do this?

  • Doesn't :e! do what you want? Nov 1, 2019 at 9:27
  • @ChristianBrabandt This does not seem to work. Rather something like :enew | e#. But I doubt it should be recommended.
    – Matt
    Nov 1, 2019 at 9:39
  • @Matt :e! has always reset the folds for me. not sure why you would recommend opening the same file in a different window so. Nov 1, 2019 at 9:58
  • @ChristianBrabandt Perhaps, you make use only of za and other such commands which influence only individual folds, but not any of the window folding options. But if you ever use zR, or something like that, then its effect of setting local foldlevel will remain after :e!
    – Matt
    Nov 1, 2019 at 10:35
  • 2
    Also zX might be helpful. Nov 1, 2019 at 10:56

1 Answer 1


would like a :refold command`

command! -range -addr=windows Refold call ResetWinOpts(<line1>, <line2>, ['fdm', 'fdl', ...])
command! RefoldAll tabdo %Refold

" reset options through a window-range to global values
function! ResetWinOpts(winid1, winid2, opts)
    call execute(printf("%s,%swindo setl %s<", a:winid1, a:winid2, join(a:opts, "< ")))

If you're only interested in undoing all effects of manual folding, like za/zo/zc etc. then, as @ChristianBrabandt suggested in the comments, the command zX will do this for you.

Your Answer

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

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