How to Clear all Whitespace in Vim

May 21 2011 by Andrew Brown

All you need to do is type:

:%s/\s\+$//

But what I think you really want to do is add this to your .vimrc file.

map cw :%s/\s\+$//

Then you can just type

\cw

and it will clear all whitespace in your current file.

Write a Comment to “How to Clear all Whitespace in Vim”