KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 code files almost all lines have trailing back spaces and I do not want to burden my code reviewer with unnecessary diff. diff -b is not a solution right now since it also ignores white spaces from anywhere in a line and sometimes that change is important enough to be include in the diff output. So my question is - is it possible to strip trailing white spaces from only the lines that have been edited in this session in a file in vim?
Tags (comma-separated)
Save Edits
Cancel