white_space.vim 679 B

123456789101112131415161718192021222324
  1. " Highlight trailing whitespace, except where still typing
  2. autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  3. autocmd InsertLeave * match ExtraWhitespace /\s\+$/
  4. " Remove trailing spaces before save
  5. autocmd BufWritePre * call StripTrailingWhitespace()
  6. function! StripTrailingWhitespace()
  7. " Save last search, and cursor position.
  8. let _s=@/
  9. let l = line(".")
  10. let c = col(".")
  11. " Do it.
  12. %s/\s\+$//e
  13. " Restore previous search history, and cursor position
  14. let @/=_s
  15. call cursor(l, c)
  16. endfunction
  17. " Add extra lines up and down
  18. nnoremap <Leader>j o<Esc>k
  19. nnoremap <Leader>k O<Esc>j
  20. " Convert tabs to spaces
  21. nnoremap <silent> <Leader><Tab> :%s/<Tab>/ /g<CR>