Automatic Clean-Up of Code in Visual Studio 2010

basti picture basti · Aug 2, 2012 · Viewed 22.3k times · Source

I am wondering, if it is possible, to have some kind of automatic code-clean-up in Visual Studio 2010.

Especially interesting would be:

  • Auto-Indent
  • Remove tailing empty lines
  • Remove unused usings

at special cases, e. g. on save of the file.

I haven't found anything in the options, but maybe I was just kinda blinded... ...afaik in eclipse it was at least possible to intend on save. There should be something like that in Visual Studio?

UPDATE: Thanks for the fast replies, the thing is that I am ware of the keyboard-shortcuts (but nevertheless thanks for mentioning), but I am working through tons of foreign code by now and it would be awesom not having to do it manually for every file :)

Answer

Dan Puzey picture Dan Puzey · Aug 2, 2012

Auto-indent can be done with Edit/Advanced/Format Document, or equivalent keyboard shortcut (Ctrl-K, Ctrl-D for me, YMMV).

Tailing empty lines I'm not aware of an automatic solution for, though there may be an extension available (or you could write your own).

Removing unused usings is a built in VS refactoring, and also available in tools like Resharper or DevExpress. (Right click code, then Organize Usings/Remove and sort.)

I'm not aware of a standard way to have these happen automatically for every document save, but you could probably write a macro or VS extension that would make this happen.