I have my .vimrc set up with indent-based folding.

But when I make additions to a file, the new text is not foldable. I can manually add folds, but I'd rather not.

Is there a way to make vim look over the file and create indent folds for all the current contents?

set foldmethod=indent
set foldenable
set foldlevel=0
augroup vimrc
  au BufReadPre * setlocal foldmethod=indent
  au BufWinEnter * if &fdm == 'indent' | setlocal foldmethod=manual | endif
augroup END
  • 2
    Are you talking about foldmethod=indent? It's not really clear what you mean. At any rate, note that foldmethod is a local option, so you probably want to set it via an ftplugin or an autocommand for the buffers that you care about (rather than setting it once in a vimrc).
    – D. Ben Knoble
    Jul 12, 2022 at 20:13
  • @D.BenKnoble I do have foldmethod set to indent. But this does not apply to indented text that was added since the file opened. Sounds like I can configure vim to set the foldmethod on write? Jul 12, 2022 at 20:23
  • 2
    I think setting foldmethod on write is probably unrelated/not what you want to do in the long run. Open a buffer with the "wrong" behavior and try :setlocal foldmethod=indent foldenable. The folds should definitely be updated as you edit text if the foldmethod is indeed indent. Also see How to debug my vimrc. How do you know it does apply to text you add? You can check folds with, for example, the foldcolumn
    – D. Ben Knoble
    Jul 12, 2022 at 20:36
  • 1
    @D.BenKnoble if I create a new js file, for example, and write some nested stuff in it, then save, then execute :setlocal foldmethod=indent foldenable, the nested stuff folds as expected. Editing answer to include foldmethod-related stuff from my .vimrc Jul 12, 2022 at 21:50

1 Answer 1


The issue was that I had some commands running on BufWinEnter that set the fold method to manual. Probably going to just manually switch modes if I actually need manual folding.

Thanks to D.BenKnoble for the breadcrumbs.

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.