Skip to content

Instantly share code, notes, and snippets.

@dhanifudin
Last active December 20, 2015 16:00
Show Gist options
  • Save dhanifudin/650aeeec3e95315b0913 to your computer and use it in GitHub Desktop.
Save dhanifudin/650aeeec3e95315b0913 to your computer and use it in GitHub Desktop.
Automatically save and remove trailing whitespace for vim
" 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