Auto Save and Load Views in vim

I often use folds in my files, especially if they're long or have complex inner structures. This can be even more useful in unit tests that have a lot of bootstrap data.

You can save these folds by running :mkview. Then when you open the file again, you can run :loadview. But this quickly gets annoying because I will more often than not forget to save the view before closing the buffer.

Let's automatically save the view on buffer exit and load the view on buffer enter.

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

Done.