I've been doing this:

au BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif

The problem is that it moves the cursor sometimes when I save the file.


Try this:

autocmd BufWritePre * %s/\s\+$//e

if you want to do this for BufReadPre as well you can


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.