Automatically save Foldings in vim

Posted on January 26, 2007 in Vim

Normaly you have to type allways :mkview and :loadview to save your folds, so simply add this two lines to your ~/.vimrc:

au BufWinLeave * silent! mkview au BufWinEnter * silent! loadview

Now, each time you close a file, its fold state will be saved and reloaded when you reopen the file in Vim.


When I open new empty files from the shell or from Vim (:new)

I get the error message:

Error detected while processing BufWinEnter Auto commands for "*":

E32: No file name

This also happens when opening :help window and sourcing sessions with

the shell command "vim -S session.vim". Have to find a way to run automatic :loadview only for windows that actually have a filename