Delete horizontal white spaces from your code in Visual Studio

Delete horizontal white spaces from your code in Visual Studio

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.

image

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.

image

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.

image

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

image

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

image

Hope this small trick helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

2 Comments to “Delete horizontal white spaces from your code in Visual Studio”

Comments are closed.