Automatically save and load Vim views / folds
Many people have written about ways of getting the Vim editor to automatically save and load views / folds. I’ve tried most of the solutions, and they all had various problems.
When placing code similar to the following in my .vimrc file usually gave me errors when opening a new tab or split:
au BufWinLeave * silent! mkview au BufWinEnter * silent! loadview
So, after reading this .vimrc file (Don’t ask me how I found it), I’ve switched to using the following instead:
set viewoptions-=options augroup vimrc autocmd BufWritePost * \ if expand('%') != '' && &buftype !~ 'nofile' \| mkview \| endif autocmd BufRead * \ if expand('%') != '' && &buftype !~ 'nofile' \| silent loadview \| endif augroup END
Voila! Error-free automatically saved folds 🙂