Last active
December 20, 2015 16:00
-
-
Save dhanifudin/650aeeec3e95315b0913 to your computer and use it in GitHub Desktop.
Automatically save and remove trailing whitespace for vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Declare ignore filetype here | |
let g:ignore_autosave = 'tex' | |
function AutoSave() | |
if &modifiable == 1 && &readonly == 0 | |
\ && expand('%') != '' | |
\ && &buftype != 'nofile' | |
%s/\s\+$//e | |
if &filetype != g:ignore_autosave | |
update | |
endif | |
endif | |
endfunction | |
autocmd InsertLeave * call AutoSave() | |
autocmd BufLeave * call AutoSave() | |
autocmd CursorHold * call AutoSave() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment