AutoSave - automatically saves changes to disk without having to use
(or any binding to it) every time a buffer has been modified or based on your
Inspired by the same feature in RubyMine text editor.
By default AutoSave will save every time something has been changed in normal mode and when the user leaves insert mode. This configuration is a mix between "save as often as possible" and "try to avoid breaking other plugins that depend on filewrite-events".
AutoSave is disabled by default, run
:AutoSaveToggle to enable/disable it.
Enable on Startup
If you want the plugin to be enabled on startup use the
" .vimrc let g:auto_save = 1 " enable AutoSave on Vim startup
It's also possible to override global
g:auto_save value individually per buffer or window. For example, if you have auto save enabled globally, you can opt out some files. And vice versa, opt in some files, when you have auto save disabled globally.
let g:auto_save = 0 augroup ft_markdown au! au FileType markdown let b:auto_save = 1 augroup END
AutoSave will display on the status line on each auto-save by default:
(AutoSave) saved at 08:40:55
You can silence the display with the
" .vimrc let g:auto_save_silent = 1 " do not display the auto-save notification
The events on which AutoSave will perform a save can be adjusted using the
g:auto_save_events option. Using
the default, will save on every change in normal mode and every time you leave insert mode.
" .vimrc let g:auto_save_events = ["InsertLeave", "TextChanged"]
Other events you may want to use:
TextChangedIwill save after a change was made to the text in the current buffer in insert mode.
CursorHoldwill save every amount of milliseconds as defined in the
updatetimeoption in normal mode.
CursorHoldIwill do the same thing in insert mode.
CompleteDonewill also trigger a save after every completion event.
Some of these commands may not be available, depending on your Vim installation.
See the autocommands overview for a complete listing (
Warning! Be advised to be careful with the
updatetime option since it has shown to
cause problems when set too small. 200 seems already to be too small to work
with certain other plugins. Use 1000 for a more conservative setting.
If you need an autosave hook (such as generating tags post-save, or aborting the save earlier)
" .vimrc " This will run :TagsGenerate after each save let g:auto_save_postsave_hook = 'TagsGenerate' " This will run AbortIfNotGitDirectory function before each save let g:auto_save_presave_hook = 'call AbortIfNotGitDirectory()' " Example hook from vim-auto-save-git-hook plugin function! AbortIfNotGitDirectory() if ... let g:auto_save_abort = 0 else let g:auto_save_abort = 1 endif endfunction
Write to All Buffers
By default only the current buffer is written (like
:w). You can choose that
all buffers are written on autosave using the
" .vimrc let g:auto_save_write_all_buffers = 1 " write all open buffers as if you would use :wa
doc/auto-save.txt is a converted version of the
README.md. Don't edit
it directly. Instead install the md2vim and
Contribution or Bug Report
Development is made in 907th/vim-auto-save repo. Please, report any bugs and/or suggestions there. Any contrubution is welcomed!
Distributed under the MIT License (see LICENSE.txt).
Copyright (c) 2013-2016 Alexey Chernenkov