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 :)

About these ads

From → Linux / Ubuntu

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: