How to trim spaces in Visual Studio 2012?

Now that macros are gone with VS 2012, what's the best way to automatically trim trailing spaces whenever a file is saved? I know that a Format Document (Ctrl-K, Ctrl-D) will do this, but it apparently modifies the file in other ways, and is it also not automated?

Motivation here:

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

+47
whitespace visual-studio-2012
Aug 25 '12 at 14:30
source share
5 answers

There are at least two extensions that can do this. One of them is CodeMaid , which explicitly truncates trailing spaces when saving, and the other is Power Tools Performance , which can work. The document format is automatically saved.

To add an extension from Visual Studio 2012, select Tools , then Extensions and Updates.. , then in the window select Online on the left and enter the search bar for CodeMaid or Productivity Power Tools in the field in the upper right corner.

+38
Jan 29 '13 at 16:11
source share

Ctrl + H
Find what:
[\ U0020] + \ r? \ N
Replaced by:
\ R \ n
\ s instead of [\ u0020] delete empty lines, probably because it matches the lines of the line ...

+20
Feb 20 '13 at 10:26
source share

You can use the Mads Kristensen Trailing Whitespace Visualizer . It has a keyboard shortcut to remove trailing spaces from the current file. Ctrl + K, Ctrl + \

Note: this is not performed when saving, you need to explicitly execute the command. On the bright side, it visually highlights offensive gaps, so it’s easier to identify cleaning options even in code that you haven’t changed.

+12
Apr 02 '15 at 23:02
source share

EditorConfig has the option to remove trailing spaces and has a Visual Studio extension. You need to add trim_trailing_whitespace = true to your .editorconfig for it to work.

+5
Jan 16 '15 at 5:39
source share

Using autoformatting hotkeys (Ctrl + A, Ctrl + K, Ctrl + F) automatically removes all trailing spaces in the file.

You can verify this by adding trailing spaces to the string and then use (Ctrl + A, Ctrl + K, Ctrl + F).

One of the lines at the bottom of the file is best, because when you use (Ctrl + A, Ctrl + K, Ctrl + F), Visual Studio will automatically jump to the end of the file. This way you can clearly see that the spaces have been removed.

0
Apr 19 '19 at 2:19
source share



All Articles