Comment and Uncomment Code
Keyboard: CTRL + K, CTRL + C (comment); CTRL + K, CTRL + U (uncomment)
Menu: Edit -> Advanced -> Comment Selection; Edit -> Advanced -> Uncomment Selection
Command: Edit.CommentSelection; Edit.UncommentSelection
Versions: 2008,2010
Published: 4/13/2010
Code: vstipEdit0047
Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!
Sometimes it's the simple stuff we forget about. So I present to you the classic Comment and Uncomment Selection. Naturally, you have the Comment and Uncomment buttons:
And, of course, we have the Menu items:
But it's the keyboard shortcuts that really rock! These will, predictably, comment or uncomment lines of code for you. So, let's say you have some code you want commented out. Just select it:
Then press CTRL + K, CTRL + C (in this example):
Voila! It's commented out. Okay, great, but what if you don't want to use the mouse? No problem! Just hold ALT + SHIFT + [UP or DOWN ARROW] to do a vertical selection (NOTE: In VS2008 you have to go right or left one character before you can go up or down for vertical selection):
Then press CTRL + K, CTRL + U (in this example):
And there you go! Comment and Uncomment actions anytime you want!
Comments
Anonymous
April 12, 2010
One more interesting thing about this is that this shortcut works in sql server as well. Also it is smart enough to know how to comment in vb, or c# or HTML. So you have to learn it only once and use it in multiple places.Anonymous
April 12, 2010
Simple one ; but one that you use regularlyAnonymous
April 12, 2010
The comment has been removedAnonymous
April 12, 2010
The comment has been removedAnonymous
April 14, 2010
I use this with SQL Server all of the time. I have put an item in the tool bar for easy access.Anonymous
June 03, 2011
Why not have it comment/uncomment without hitting a combination of keys like you're playing a Street Fighter game? Ctrl K and then Ctrl C? Why not Ctrl+Shift+C or something similar?Anonymous
June 04, 2011
Hey Michael :) You can always rebind the keys to anything you want. See this post for more information: blogs.msdn.com/.../keyboard-shortcuts-creating-new-shortcuts-vstiptool0063.aspx ZAnonymous
July 11, 2011
The comment has been removedAnonymous
November 17, 2013
in vb.net, when you type 3 times ' on top of a function, class or property, then vb.net will autogenerate a comment : ''' <summary> ''' ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks>Anonymous
January 29, 2015
<script>window.alert(“test”)</script>Anonymous
February 12, 2015
The comment has been removed