How can I trim trailing whitespace in Visual Studio 2012?

Hemmer picture Hemmer · Aug 25, 2012 · Viewed 36.2k times · Source

Now that macros are gone from Visual Studio 2012, what is the best way to automatically trim trailing whitespace whenever a file is saved?

I'm aware that Format Document (Ctrl + K, Ctrl + D) will do this, but it presumably changes the file in other ways, and it's not automatic either.

The motivation is given here:

http://codeimpossible.com/2012/04/02/trailing-whitespace-is-evil-don-t-commit-evil-into-your-repo/

Answer

Bill A picture Bill A · Jan 29, 2013

There are at least two extensions that can do this. One is CodeMaid which explicitly will trim trailing blanks on save, and the other is Productivity Power Tools which can run the Format Document automatically on save.

To add an extension from within Visual Studio 2012, select the Tools menu, then Extensions and Updates.., then in the window select Online on the left and enter your search string for CodeMaid or Productivity Power Tools in the box on the upper-right.