Delete horizontal white spaces from your code in Visual Studio

By | February 9, 2016

While writing code, pasting snippet from other sources we may ended up some additional spaces after end of the line or middle of the line. Sometime we added few extra spaces added due mistakenly holding the space bar for long. Of course you may not want them to be there.  Most of the time, I have seen developers ended up by pressing backspace to get rid of them.  Well, you can directly remove all the extra white spaces after end of each line from the code. This is another overlooked feature in Visual Studio and often missed by the developer.

Well, place the cursor into the line from where you want to clean it up and then navigate to Edit -> Advanced -> Delete Horizontal White Space or press Ctrl + E , \ . That will automatically remove the additional spaces from your code.


As this is really an overlooked feature and we ended up pressing backspace to clean this.

Must Read: 9 Hidden Features of Visual Studio that you should know

Consider you have following code blocks, and below highlighted part has additional white spaces.


Now, if you keep your cursor at the end of the line and press “Ctrl+E,\”. You will find all the additional spaces has been removed.


If you put them together, this is how it’s looks like.


As I said earlier, this also works well, when the spaces are in the middle of you code elements.


Hope this small trick helps !

2 thoughts on “Delete horizontal white spaces from your code in Visual Studio

  1. Pingback: Where the white spaces are in my code ?– Automatically indicates white spaces in Visual Studio

  2. Pingback: Dew Drop – February 10, 2016 (#2185) | Morning Dew

Comments are closed.