```
" Strip trailing whitespace
function! StripTrailingWhitespaces()
" Skip these
if &ft =~ '\|slim|haml'
return
endif
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
autocmd BufWritePre * :call StripTrailingWhitespaces()
```