Visual Studio Tricks


Visual Studio (2005,2008,2010) Tips and Tricks.


#17 Keyboard Shortcut to Comment and Uncomment Code

Commenting code is great. We all do it, all day long. Commonly I’ll see the following done to comment multiple lines of C# code.

[HOME]+[//],[UP],[HOME],<Repeat />

This just takes too long. It’s too many keystrokes. This Quick 2 minute video shows you all about commenting, and uncommenting, and even has an added little trick to know about ASP.NET (ASPX) Commenting.

Click Screenshot To Play Video

#17 Keyboard Shortcut to Comment and Uncomment Code

Runtime: 2Min 12 Seconds - Resolution: 900 by 580 - File Size: 2.8Meg

Direct Download: If the video does not work for you,
Click Here to download it.

Snippets / Notes:

[CTRL]+[K],[C] = Comment the current line, or selected lines of code

[CTRL]+[K],[U] = Uncomment the current line, or selected lines of code

Visual Studio Tip / Trick #017 English Transcription:

Today’s Visual Studio trick is Keyboard shortcuts for commenting and uncommenting Code. It's trick nunmber 17 which was originally published by Sara Ford in text in August 2007. To comment and uncomment code you use the keyboard combination [CTRL]+[K],[C] to comment and [CTRL]+[K],[U] to uncomment. NOw if you do not have anything selected then the current line of code will be commented for you. If you have more than one line of code selected [CTRL]+[K],[C] and [CTRL]+[K],[U] will comment and uncomment respectively. Now we're in C# file but watch if we jump over to CSS file and we do a [CTRL]+[K],[C]? It doesn’t work for us but if we move into a javascript file [CTRL]+[K],[C] knows how to comment. So there are certain types of files where comments work and certain files where comment do not work. I know it works in Visual Basic, C#, Javascript and also ASPX files. So lets just quickly navigate to an ASPX file and if we highlight a piece of server side code and do [CTRL]+[K],[C] you'll see that there is a server comment that is wrapped around the HTML. Now a server comment is different in ASP.net than a regular comment. A Server comment is actually nothing rendered to the output where a regular HTML comment does get rendered in the output. Where a server side comment does not. So a little bit of a tip/trick on ASP.net as well as [CTRL]+[K],[C] to comment and [CTRL]+[K],[U] to uncomment. That is also available on the Edit menu, if you jump down to the Advance Tools you can see there is a comment and uncomment selection.
Kick this Trick on DotNetKicks.com

2 comment(s)

  1.  avatar

    Audio plays, but screen doesn't advance (I get one screenshot -- so far, only one like this that I've found).

  2.  avatar

    Check that. Completely closed browser and tried again. "Works very much good!"


RSS Feeds

All Technology Posts

Scott Cate Main Blog Feed


Visual Studio Tricks Only Feed

@ScottCate on Twitter

Twitter @ScottCate

  • Today is a good day!
  • @blaken i already like @codesmithtools :)
  • @pacitpros is hosting a 2 day IT Pro Conference in San Francisco March 22-23rd, 2012 Tech Days http://t.co/2igpJikF
  • Can you help me get to a quick 25 likes for #Mykb on Facebook? http://t.co/0WSh2GdZ
  • Meeting Planner Meltdown via/ @EventDay evn.tc/xpXHnP #Engage365 #EventProfs