From 423a65bf139445069afc18160130a2c16c01b60e Mon Sep 17 00:00:00 2001 From: Ein Verne Date: Sat, 2 Feb 2019 10:09:58 +0800 Subject: [PATCH] Add auto save --- .vimrc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.vimrc b/.vimrc index 40d366b..52a5dae 100644 --- a/.vimrc +++ b/.vimrc @@ -243,11 +243,29 @@ set t_Co=256 " let g:Powerline_symbols='fancy' " autosave when lost focus -:au FocusLost * silent! wa -:au FocusLost * :wa +au FocusLost * silent! wa +au FocusLost * :wa + +autocmd TextChanged,TextChangedI silent write autocmd CursorHold, CursorHoldI * update +" save on buffer switch +set autowrite +set autowriteall + +let g:autosave_time_period = 10 +au BUfRead,BufNewFile * let b:start_time=localtime() +" only write if needed and update the start time after save +function! UpdateFile() + if ((localtime() - b:start_time) >= g:autosave_time_period) + update + echo "Time: " . (localtime() - b:start_time) . " seconds have elapsed. File saved." + let b:start_time=localtime() + endif +endfunction +au CursorHold * call UpdateFile() + " general mapping " no ddkP " no ddp