Removing trailing white space only for edited lines
I had added the following function in my .vimrc for removing trailing white spaces just before saving fun! <SID>StripTrailingWhitespaces() let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfun autocmd BufWritePre *.h :call <SID>StripTrailingWhitespaces() autocmd BufWritePre *.cpp :call <SID>StripTrailingWhitespaces() autocmd BufWritePre *.c :call <SID>StripTrailingWhitespaces() It works really well. However, in certain cases I would like to remove trailing white spaces only from lines that I have edited. This is to ensure that my diff output looks sane as for certain legacy