Skip to content

Automatically save and load Vim views / folds

March 30, 2011

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 šŸ™‚


From → Linux / Ubuntu

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: