├── README ├── README.md ├── doc └── LICENSE.txt └── plugin └── AutoSave.vim /README: -------------------------------------------------------------------------------- 1 | This is a mirror of http://www.vim.org/scripts/script.php?script_id=4521 2 | 3 | AutoSave - automatically save changes to disk without having to use :w (or any binding to it) every time a buffer has been modified. 4 | AutoSave is disabled by default, run :AutoSaveToggle to enable/disable AutoSave. 5 | If you want plugin to be always enabled it can be done with g:auto_save option (place 'let g:auto_save = 1' in your .vimrc). 6 | Inspired by the same feature in RubyMine text editor. 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoSave 2 | 3 | ## Description 4 | 5 | AutoSave - automatically save changes to disk without having to use `:w` (or any binding to it) every time a buffer has been modified. 6 | 7 | Inspired by the same feature in RubyMine text editor. 8 | 9 | ## Installation and Usage 10 | 11 | Use [vundle](https://github.com/gmarik/vundle) or 12 | download [packaged version](http://www.vim.org/scripts/script.php?script_id=4521) from vim.org. 13 | 14 | AutoSave is disabled by default, run `:AutoSaveToggle` to enable/disable it. 15 | If you want plugin to be always enabled it can be done with `g:auto_save` option: 16 | 17 | ```VimL 18 | " .vimrc 19 | let g:auto_save = 1 " enable AutoSave on Vim startup 20 | 21 | ``` 22 | 23 | AutoSave relies on `CursorHold` event and sets the `updatetime` option to 200 so that modifications are saved almost instantly. 24 | But sometimes changing the `updatetime` option may affect other plugins and break things. 25 | You can prevent AutoSave from changing the `updatetime` with `g:auto_save_no_updatetime` option: 26 | 27 | ```VimL 28 | " .vimrc 29 | let g:auto_save_no_updatetime = 1 " do not change the 'updatetime' option 30 | 31 | ``` 32 | 33 | You can disable AutoSave in insert mode with the `g:auto_save_in_insert_mode` option: 34 | 35 | ```VimL 36 | " .vimrc 37 | let g:auto_save_in_insert_mode = 0 " do not save while in insert mode 38 | 39 | ``` 40 | 41 | AutoSave will display on the status line on each auto-save by default. 42 | 43 | ``` 44 | (AutoSaved at 08:40:55) 45 | ``` 46 | 47 | You can silence the display with the `g:auto_save_silent` option: 48 | 49 | ```VimL 50 | " .vimrc 51 | let g:auto_save_silent = 1 " do not display the auto-save notification 52 | 53 | ``` 54 | 55 | If you need an autosave hook (such as generating tags post-save) then use `g:auto_save_postsave_hook` option: 56 | 57 | ```VimL 58 | " .vimrc 59 | let g:auto_save_postsave_hook = 'TagsGenerate' " this will run :TagsGenerate after each save 60 | 61 | ``` 62 | 63 | ## Contribution 64 | 65 | Development is made in [907th/vim-auto-save](https://github.com/907th/vim-auto-save) repo. 66 | Feel free to contribute! 67 | 68 | ## License 69 | 70 | Distributed under the MIT License (see LICENSE.txt). 71 | 72 | Copyright (c) 2013-2014 Alexey Chernenkov 73 | -------------------------------------------------------------------------------- /doc/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Alexey Chernenkov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /plugin/AutoSave.vim: -------------------------------------------------------------------------------- 1 | "====================================== 2 | " Script Name: vim-auto-save (http://www.vim.org/scripts/script.php?script_id=4521) 3 | " Plugin Name: AutoSave 4 | " Version: 0.1.7 5 | "====================================== 6 | 7 | if exists("g:auto_save_loaded") 8 | finish 9 | else 10 | let g:auto_save_loaded = 1 11 | endif 12 | 13 | let s:save_cpo = &cpo 14 | set cpo&vim 15 | 16 | if !exists("g:auto_save") 17 | let g:auto_save = 0 18 | endif 19 | 20 | if !exists("g:auto_save_no_updatetime") 21 | let g:auto_save_no_updatetime = 0 22 | endif 23 | 24 | if !exists("g:auto_save_in_insert_mode") 25 | let g:auto_save_in_insert_mode = 1 26 | endif 27 | 28 | if g:auto_save_no_updatetime == 0 29 | set updatetime=200 30 | endif 31 | 32 | if !exists("g:auto_save_silent") 33 | let g:auto_save_silent = 0 34 | endif 35 | 36 | augroup auto_save 37 | autocmd! 38 | if g:auto_save_in_insert_mode == 1 39 | au CursorHoldI,CompleteDone * nested call AutoSave() 40 | endif 41 | au CursorHold,InsertLeave * nested call AutoSave() 42 | augroup END 43 | 44 | command! AutoSaveToggle :call AutoSaveToggle() 45 | 46 | function! AutoSave() 47 | if g:auto_save >= 1 48 | let was_modified = &modified 49 | silent! wa 50 | if was_modified && !&modified 51 | if exists("g:auto_save_postsave_hook") 52 | execute "" . g:auto_save_postsave_hook 53 | endif 54 | if g:auto_save_silent == 0 55 | echo "(AutoSaved at " . strftime("%H:%M:%S") . ")" 56 | endif 57 | endif 58 | endif 59 | endfunction 60 | 61 | function! AutoSaveToggle() 62 | if g:auto_save >= 1 63 | let g:auto_save = 0 64 | echo "AutoSave is OFF" 65 | else 66 | let g:auto_save = 1 67 | echo "AutoSave is ON" 68 | endif 69 | endfunction 70 | 71 | let &cpo = s:save_cpo 72 | unlet s:save_cpo 73 | --------------------------------------------------------------------------------