Today I learned how to fold/unfold in Vim; it's quite handy.
Unexpectedly, when I exit a file and reenter it, the folds I created are gone (unfolded).
In our company's large project there are quite a lot of sticky (legacy) code blocks which are kind of obsolete but indispensable.
I really need to fold them nearly permanently.
Is there a brief way to tell Vim to save my folding preferences for a file?
:mkview
and:loadview
commands could help. You could try adding these 2 lines inside your vimrcau BufWinLeave *.c mkview
andau BufWinEnter *.c silent loadview
and adapt them to your specific needs. These are autocommands that will be automatically executed whenever you leave a buffer for the first one, and when you enter a buffer for the second one, but only for C files. I've copied them from the help of the:mkview
command (:help :mkview
).'viewoptions'
containsfolds
. If you want the autocommands to be executed for other filetypes, you can change the autocommands. For example, if you want to add python files, you could change*.c
to*.c,*.py
.