From 04ce579f61fc60e8cba9fb92d05e4cb15aa7fbca Mon Sep 17 00:00:00 2001 From: amix Date: Sat, 1 Apr 2017 14:12:35 +0200 Subject: [PATCH] Fixed https://github.com/amix/vimrc/issues/263 --- vimrcs/basic.vim | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vimrcs/basic.vim b/vimrcs/basic.vim index 6c1d423c..b783aef3 100644 --- a/vimrcs/basic.vim +++ b/vimrcs/basic.vim @@ -299,14 +299,18 @@ if has("mac") || has("macunix") vmap endif -" Delete trailing white space on save, useful for Python and CoffeeScript ;) -func! DeleteTrailingWS() - exe "normal mz" - %s/\s\+$//ge - exe "normal `z" -endfunc -autocmd BufWrite *.py :call DeleteTrailingWS() -autocmd BufWrite *.coffee :call DeleteTrailingWS() +" Delete trailing white space on save, useful for some filetypes ;) +fun! CleanExtraSpaces() + let save_cursor = getpos(".") + let old_query = getreg('/') + silent! %s/\s\+$//e + call setpos('.', save_cursor) + call setreg('/', old_query) +endfun + +if has("autocmd") + autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces() +endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""