From 55b5394efdea2e3edecdedafc56e35fbb013c697 Mon Sep 17 00:00:00 2001
From: "lilei (Cloud)"
Date: Fri, 7 Sep 2018 19:12:41 +0800
Subject: [PATCH] vimrc: modify StripTrailingWhitespace.
Signed-off-by: lilei (Cloud)
---
vimrc | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/vimrc b/vimrc
index c75f41f..03901a2 100644
--- a/vimrc
+++ b/vimrc
@@ -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
- 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()
-