Paul D. Eden Paul D. Eden - 1 year ago 113
Git Question

How can you automatically remove trailing whitespace in vim

I am getting 'trailing whitespace' errors trying to commit some files in git.

I want to remove these trailing whitespace characters automatically right before I save python files.

Can you configure vim to do this? If so, how?

Answer Source

I found the answer here.

Adding the following to my .vimrc file did the trick.

autocmd BufWritePre *.py :%s/\s\+$//e
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download