Skip to content

Commit

Permalink
vimrc: modify StripTrailingWhitespace.
Browse files Browse the repository at this point in the history
Signed-off-by: lilei (Cloud) <[email protected]>
  • Loading branch information
lilei (Cloud) authored and lilei (Cloud) committed Sep 7, 2018
1 parent 9159b4c commit 55b5394
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,18 @@ function! ReplaceTab()
endif
endfunction

" remove unwanted whitespace
" http://vim.wikia.com/wiki/Remove_unwanted_spaces
" However, this has minor side-effects, such as influencing undo history
" and sometimes changing scroll position.
" remove unwanted whitespace
" https://github.com/spf13/spf13-vim.git
function! StripTrailingWhitespace()
if !&binary && &filetype != 'diff'
normal mz
normal Hmy
%s/\s\+$//e
normal 'yz<CR>
normal `z
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 StripTrailingWhitespace()


0 comments on commit 55b5394

Please sign in to comment.