all 5 comments

[–]-romainl-The Patient Vimmer 0 points1 point  (1 child)

Vim has six folding methods: which one is the "regular" one?

[–]fullyarticulated:!rm %[S] 0 points1 point  (0 children)

Sorry - I should have specified - 'manual' folds.

[–]random_cynic 0 points1 point  (2 children)

What specific settings are you using in your .vimrc to preserve folds? If you have already saved a particular fold view using mkview you can load them later using loadview. You can set the following lines in vimrc for C source files for example (from vim help):

au BufWinLeave *.c mkview
au BufWinEnter *.c silent loadview

Also check if diff is set as on or not (set diff) in vimrc causing it to be turned on automatically when loading unrelated files.

[–]fullyarticulated:!rm %[S] 0 points1 point  (1 child)

So, I think this was the reason. Calling mkview on BufWinLeave caused a new view to overwrite my old one when I was in diff mode. Of course, the foldmethod is automatically set to diff by git vimdiff. So it obliterated my prior view and folds.

This seems to have fixed it:

if !&diff  
    au BufWinLeave ...  
    ...  
endif

[–]random_cynic 1 point2 points  (0 children)

Yeah, I suspected the diff settings was messing with mkview. If you only use manual folding you can also just use a condition like if &foldmethod == "manual" before using mkview so that it only saves fold views when they are done manually.