I'd like vim to automatically write my file as often as possible. The ideal would be every keystroke.
I need to save regularly so that my background build process will see it. It's a makefile for a latex document, and I'd like the previewer to show me a nearly up-to-date document when I'm finished typing.
Eventual answer (the answers below helped make this)
" Choose your own statusline here
let g:pbstatusline="%F\ %y\ %l:%c\ %m"
set statusline=%F\ %y\ %l:%c\ %m
autocmd FileType tex setlocal autowriteall
" Save the file every 5 keypresses
autocmd FileType tex setlocal statusline=%!pb:WriteFileViaStatusLine()
" Save the file every time this event fires.
autocmd FileType tex :autocmd InsertLeave,CursorHold,CursorHoldI * call pb:WriteFileViaStatusLine("always")
" 1 optional param: "always" is only allowed value.
let s:writefilecounter = 0
function! pb:WriteFileViaStatusLine(...)
if s:writefilecounter > 5 || (a:0 > 0 && a:1 == "always")
if &buftype == ""
write
endif
let s:writefilecounter = 0
else
let s:writefilecounter = s:writefilecounter + 1
endif
return g:pbstatusline
endfunction