Improved Autosave

This commit is contained in:
Talia 2018-02-15 09:06:47 +01:00
parent f66850906b
commit 05579eaa8c

25
vimrc
View file

@ -533,20 +533,25 @@ function! s:toggleWUC()
endfunction endfunction
" Autosave when vim loses focus :) " Autosave when vim loses focus :)
function! TryAutosave(warn, single) function! TryAutosave(warn, mode)
if &autowriteall==1 if &autowriteall==0 " All buffers
if a:single if a:mode == 0
silent wall
if a:warn
echo "Autosaving all buffers..."
end
elseif a:mode == 1
silent wall " Lie to the user and save everything :)
if a:warn
echo "Autosaving all buffers in tab..."
end
elseif a:mode == 2
if &mod if &mod
silent write silent write
if a:warn if a:warn
echo "Autosaving current buffer..." echo "Autosaving current buffer..."
end end
end end
else
silent wall
if a:warn
echo "Autosaving all buffers..."
end
end end
redraw redraw
endif endif
@ -554,7 +559,9 @@ endfunction
augroup autosave augroup autosave
autocmd! autocmd!
autocmd FocusLost * call TryAutosave(0, 0) autocmd FocusLost * call TryAutosave(0, 0)
autocmd CursorHold * call TryAutosave(0, 1) autocmd TabLeave * call TryAutosave(0, 1)
autocmd BufLeave * call TryAutosave(0, 2)
autocmd CursorHold * call TryAutosave(0, 2)
augroup END augroup END
vnoremap <leader>g :<C-u>call <SID>GrepOperator(visualmode())<CR> vnoremap <leader>g :<C-u>call <SID>GrepOperator(visualmode())<CR>