Vim Tweaks

Automatically save and load files

Posted by Grego on January 18, 2015

Today’s short tweak is going to “modernize” our vim for coding by adding automatic saving and loading. While not for everyone, I’m just here to demonstrate that it’s possible. I’ve been using it for a couple of days and so far I like it.


Add the following to your ~/.vimrc or the ftplugin/after of your choice:

au FocusLost * :wa

This will automatically save files when focus is lost, with the exception of unnamed buffers. If you want to ignore unnamed buffers and continue saving, use this:

:au FocusLost * silent! wa

Check the vim wiki for more information on auto saving.


To automatically load the files when the filesystem updates:

set autoread

From the documentation (:h autoread):

When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again. When the file has been deleted this is not done.