Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Propt to remove trailing whitespaces

  • Loading branch information...
commit 12a23fe2142e6bfd2c3ffeb27e90e1501676dfef 1 parent e46272e
@graudeejs authored
Showing with 26 additions and 1 deletion.
  1. +26 −1 vimrc
View
27 vimrc
@@ -86,6 +86,29 @@ function! DoIHaveDotDirInPath()
endfunction
"}}}
+" PromptRemoveTrainingWhitespace() {{{
+
+function! PromptRemoveTrainingWhitespace()
+ let has_trailing_spaces=!!search('\v\s+$', 'cwn')
+ if has_trailing_spaces
+ if ! exists("b:remove_trailing_whitespace")
+ let has_trailing_spaces=!!search('\v\s+$', 'cwn')
+ if has_trailing_spaces
+ let choice = confirm("Remove trailing whitespace?", "&Yes\n&No")
+ if choice == 1
+ call RemoveTrainingWhitespace()
+ let b:remove_trailing_whitespace = 1
+ else
+ let b:remove_trailing_whitespace = 0
+ endif
+ endif
+ elseif b:remove_trailing_whitespace == 1
+ call RemoveTrainingWhitespace()
+ endif
+ endif
+endfunction
+
+"}}}
" RemoveTrainingWhitespace() {{{
function! RemoveTrainingWhitespace()
@@ -99,6 +122,8 @@ function! RemoveTrainingWhitespace()
endfunction
"}}}
+
+
" ProgrPath(prog_list) {{{
function! ProgrPath(prog_list)
@@ -316,7 +341,7 @@ let &viminfo .= ",r~/mnt,r/mnt,r/media,r/cdrom,<500,f1,'200,n" . vim_var . "/vim
" Resize vindows if vim is resized
autocmd VimResized * exe "normal! \<c-w>="
-autocmd BufWritePre * call RemoveTrainingWhitespace()
+autocmd BufWritePre * call PromptRemoveTrainingWhitespace()
if isdirectory('/usr/share/dict')
for dictionary in ['words', 'web2a', 'propernames', 'freebsd']
Please sign in to comment.
Something went wrong with that request. Please try again.