Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I make CTRL + / toggle a comment in Visual Studio, as it does with XCode and Eclipse?

share|improve this question
up vote 14 down vote accepted

You can't make it toggle without going into either a macro or other VS extension.

However, I always setup VS to comment with Ctrl + / and uncomment to Ctrl + Shift + /

You can customize the keyboard shortcuts by going int the "Tools" menu and selecting "Options". Then select "Keyboard" from the "Environment" branch. From there you can bind the Edit.CommentSelection and Edit.UncommentSelection commands to whichever keyboard shortcuts you'd like.

share|improve this answer
Every other IDE that exists uses Ctrl+/ ... why-oh-Microsoft-why! – MikeMurko Nov 1 '15 at 14:02

If you have ReSharper installed (and using VS without it is/was tedious), you can assign a single key to the command ReSharper.ReSharper_LineComment.

For instance, I bind the keyboard shortcut Ctrl-K, Ctrl-C to the command, and then if I use it on a line that is uncommented, it comments it, and if the line is commented, it will uncomment it.

enter image description here

share|improve this answer
+1 for the ReSharper option – Itay Gal Jun 17 '15 at 13:45
so to directly answer the original question, assign CTRL + / to ReSharper.ReSharper_LineComment – Chin Mar 9 at 1:59

Ctrl-K and Ctrl-C will comment one or more selected lines.

Ctrl-K and Ctrl-U will uncomment one or more selected lines.

You can get toolbar icons that will do this by adding the "Text Editor" toolbar. In the toolbar area right-click and select "Text Editor" This will add a strip of icon buttons like this:

enter image description here

You can customize this strip by selecting the dropdown at the end of the ribbon:

enter image description here

To edit the keyboard combination go to Tools-Options and select Keyboard under the Environment tree. Here you can change the keys used to trigger the Comment and Uncomment actions:

enter image description here

share|improve this answer
In a default install this shortcut will just comment, not uncomment. – heavyd Feb 14 '13 at 16:28
Clarified key combinations – Brad Patton Feb 14 '13 at 16:39
Edit.CommentSelection doesn't show up in VisualStudio 2015 community edition. – allan ruin Jul 30 '15 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .