Move Autosave into plugin and make more aggressive
This commit is contained in:
parent
d1437b0b06
commit
b989ac1cda
2 changed files with 19 additions and 30 deletions
19
vim/plugin/autosave.vim
Normal file
19
vim/plugin/autosave.vim
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
" Extend autosavefeature :)
|
||||||
|
|
||||||
|
function! TryAutosave()
|
||||||
|
if &autowriteall
|
||||||
|
if &mod
|
||||||
|
silent write
|
||||||
|
end
|
||||||
|
redraw
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
augroup autosave
|
||||||
|
autocmd!
|
||||||
|
autocmd BufLeave * call TryAutosave()
|
||||||
|
autocmd CursorHold * call TryAutosave()
|
||||||
|
autocmd InsertLeave * call TryAutosave()
|
||||||
|
autocmd TextChanged * call TryAutosave()
|
||||||
|
autocmd FocusLost * call TryAutosave()
|
||||||
|
augroup END
|
|
@ -688,36 +688,6 @@ function! s:toggleWUC()
|
||||||
redraw
|
redraw
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Autosave when vim loses focus :)
|
|
||||||
function! TryAutosave(warn, mode)
|
|
||||||
if a:mode == 0
|
|
||||||
if &autowriteall || &autowrite
|
|
||||||
silent wall
|
|
||||||
if a:warn
|
|
||||||
echo "Autosaving all buffers..."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif a:mode == 1
|
|
||||||
if &autowriteall
|
|
||||||
if &mod
|
|
||||||
silent write
|
|
||||||
if a:warn
|
|
||||||
echo "Autosaving current buffer..."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
redraw
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
augroup autosave
|
|
||||||
autocmd!
|
|
||||||
autocmd FocusLost * call TryAutosave(0, 0)
|
|
||||||
autocmd BufLeave * call TryAutosave(0, 1)
|
|
||||||
autocmd CursorHold * call TryAutosave(0, 1)
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
vnoremap <leader>g :<C-u>call <SID>GrepOperator(visualmode())<CR>
|
vnoremap <leader>g :<C-u>call <SID>GrepOperator(visualmode())<CR>
|
||||||
nnoremap <leader>g :set operatorfunc=<SID>GrepOperator<CR>g@
|
nnoremap <leader>g :set operatorfunc=<SID>GrepOperator<CR>g@
|
||||||
function! s:GrepOperator(type)
|
function! s:GrepOperator(type)
|
||||||
|
|
Loading…
Reference in a new issue