trailingspace.vim 802 B

123456789101112131415161718192021222324252627282930
  1. " Trailing Space - Modeline and Notes {{{
  2. " vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
  3. "
  4. " cinaeco/dotfiles Trailing space removal
  5. "
  6. " Taken from spf13-vim
  7. "
  8. " }}}
  9. " Remove trailing spaces before save {{{
  10. if has("autocmd")
  11. " Are there really any files we care about that Need trailing white space?
  12. "autocmd FileType c,cpp,java,go,php,javascript,python,twig,xml,yml
  13. autocmd BufWritePre * call StripTrailingWhitespace()
  14. function! StripTrailingWhitespace()
  15. " Preparation: save last search, and cursor position.
  16. let _s=@/
  17. let l = line(".")
  18. let c = col(".")
  19. " do the business:
  20. %s/\s\+$//e
  21. " clean up: restore previous search history, and cursor position
  22. let @/=_s
  23. call cursor(l, c)
  24. endfunction
  25. endif
  26. " }}}