I added the following code to my .vimrc:
\" save and restore folds when a file is closed and re-opened
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* sil
Add this to the top of your vimrc to make sure the viewdir is present
let &viewdir=expand("$HOME") . "/.bk/.vim/viewdir"
if !isdirectory(expand(&viewdir))|call mkdir(expand(&viewdir), "p", 451)|endif
Then this in your autocmds section:
autocmd BufWrite * mkview
autocmd BufNewFile,BufRead * silent loadview