From time to time, I'll open up a document in vim and find that my manual folds are completely messed up. It's like vim decides to ignore its usual markers and, instead, start interpreting random bits of text as being fold points.

In the past, I've been able to essentially ignore the issue and, eventually, vim will come to its senses next time I open up the file. Currently, this is NOT the case and I'm at the point where I need to finally get down to resolving whatever issue may be in play.

Here are the relevant portions of my .vimrc

"folding -----------------"{{{
set foldenable
" set foldlevelstart=99
" set foldnestmax=10 " 10 nested folds max

" NOTE: Enable only one of the below methods at a time
" set foldmethod=manual
" set foldmethod=indent
" set foldmethod=expr " fold per REGEX
set foldmethod=marker " persistent folds based on saved marker positions
" set foldmethod=syntax
" set foldmethod=diff " recommended to never set it this way manually. You
                      " can enter this fold mode by going into vim diff mode

" NOTE: Uncomment the below to remember fold settings
" if !has('nvim')
"   augroup RememberFolds " remember fold settings
"     autocmd!
"     autocmd BufWinLeave ?* mkview
"     autocmd BufWinEnter ?* silent loadview
"   augroup END
" endif

"Sets Space as the key to open/close folds as long as cursor is on a fold
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf


I also have the vimwiki plugin enabled, though I'm not currently using it (the file in question is not a vimwiki related file). I only mention that because I do have this noted

let g:vimwiki_folding='' " <blank>, expr, syntax, list
  " NOTE: Evidently vimwiki will use whatever you set vim's fold settings to if you leave this setting as '' (ie blank). So
  " in order to have vimwiki respond to manual fold settings like I have in vim, leaving it blank seemed to do the trick
  " when vim's fold setting is set to marker

Here are some screenshots to show what I'm talking about. Note the text it should be keying into for folding are variations of the {{{ }}} pairs

enter image description here

enter image description here

enter image description here

Any ideas for what I can try? Thank you in advance for your help!

UPDATE: I just noticed that when setting new folds, vim is using < > pairs rather than the previous handlebar pairs. Researching now!

  • You have autocommands for mkview/loadview (which I cannot recommend: sessions work better). Try removing those or deleting the view file.
    – D. Ben Knoble
    Nov 25, 2020 at 17:10
  • 1
    Yes, that portion is commented out. I've long since moved to sessions. Thanks for the pointer just in case!
    – Spectator6
    Nov 25, 2020 at 17:20
  • 1
    From your edit, you might try :verbose set foldmarker?
    – D. Ben Knoble
    Nov 25, 2020 at 17:21
  • 1
    D Ben Knoble, you glorious being! That did it! Turns out my last Session.vim file somehow had a line in it that changed the fold marker! Once I deleted it, I'm back in action! :) Thank you thank you! Submit as an answer and I'll upvote
    – Spectator6
    Nov 25, 2020 at 17:24

1 Answer 1


Based on some information in the comments and the text re: folding on <>, I suggested

verbose set foldmarker?

(foldmarker being the option that controls what "marker" to use when foldmethod=marker)

The OP confirmed in comments that a line in a session file was changing this; deleting it did the trick.

  • 2
    Thank you Ben! high fives
    – Spectator6
    Nov 25, 2020 at 17:28

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.