How can I make CTRL + / toggle a comment in Visual Studio, as it does with XCode and Eclipse?
10 Answers
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.
- 61,031
- 17
- 150
- 172
-
This should be the accepted answer, and still works in Aug 2020 – olonge Aug 29 '20 at 20:18
Here is a plugin to have the almighty "Toggle Comment" command...
1- Download and Install > https://marketplace.visualstudio.com/items?itemName=munyabe.ToggleComment
2- Restart VS
3- Go to "Tools > Options... > Environment > Keyboard"
4- Search for the command "ToggleComment" & Bind it to your favorite key
5- Enjoy
(Thank you, I had gave up but finally found this easy way to do it ;D)
- 571
- 5
- 3
-
2
-
7The secret to making this work was selecting `TextEditor` rather than `global` before pressing `Assign`. – Gulzar Jul 16 '20 at 12:53
-
-
Toggle single line comment and toggle block comment commands have been added in VS 2019 for C#
You can change the shortcut for these commands to whatever you want in Tools -> Options -> Environment -> Keyboard, search for Edit.ToggleBlockComment or Edit.ToggleLineComment.
- 446
- 4
- 4
-
5Oddly, they do not work, not even the defaults, in VS 16.2.2. The error "`The key combination (Ctrl-K, Ctrl-/) is bound to command (Toggle Line Comment) which is not currently available.`" appears at the bottom in the status bar for the default keystrokes, and it doesn't even do that much if you use a custom one. For now, I'll be giving the "Toggle Comment" plugin a try. – MartyMacGyver Aug 19 '19 at 06:03
-
1This did work for me and if you have VS 2019 is the best solution, actually, is THE solution. VS 12.2.5 – Norcino Oct 04 '19 at 14:44
-
1
-
1
-
1This still works in VS 2022. It's insane that this isn't a default yet. – JD Byrnes Feb 06 '22 at 06:47
-
-
Get this to the top: In C#, Ctrl+k creates breakpoints: breakpoints don't respond to `Edit.ToggleBlockComment` or Ctrl+/. – Wolfpack'08 Sep 01 '22 at 09:51
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.

- 432
- 1
- 5
- 7
-
3so to directly answer the original question, assign `CTRL + /` to `ReSharper.ReSharper_LineComment` – Chin Mar 09 '16 at 01:59
-
You can also create custom shortcuts using above procedure by placing keys inside 'Press shortcuts keys', step by step procedure here: https://qawithexperts.com/article/c-sharp/useful-visual-studio-shortcuts-comment-remove-comment-collap/309 – Vikas Lalwani Jul 31 '21 at 08:41
Apparently, VS2019 has finally introduced alternative keyboard mapping schemes.
They're available at Options -> Environment -> Keyboard.
I've been looking for a solution for toggle comment shortcut problem and I got a whole surprise package. This is more than I wanted.

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:

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

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:

- 10,440
- 12
- 39
- 68
-
-
-
Edit.CommentSelection doesn't show up in VisualStudio 2015 community edition. – allan ruin Jul 30 '15 at 14:53
If you're using Resharper, there is an almost identical alternative:
Right Alt+/
By using this single shortcut, you can simply toggle between commenting/uncommenting code.
- 23,925
- 11
- 103
- 209
- 121
- 1
- 7
In Visual Studio Code 2019, this can be done by:
- Enter
hotkeysin the IDE search field and clickChange hotkeys and keyboard shortcuts. - In
Show commands containing, search for and selectEditorContextMenus.CodeWindow.GenerateDocumentationComments. - Click
Removeon the right side ofShortcuts for selected command, wherectrl+/is currently selected. - In
Show commands containing, search for and selectEdit.ToggleLineComments. - Click the
Press shortcut keysbox and pressctrl+/. - Click
Assignto assign the new hotkey.
Note that unbinding the already existing function for ctrl + / is necessary for this to work.
- 111
- 1
-
Steps 1-3 are sufficient in latest VS2019, which has `ctrl` + `/` as the Global default for `Edit.ToggleLineComments`. – victorlin Nov 18 '20 at 15:56
-
I don't know if it is the same in 2012 but in 2015 you can.
Go to Tools > Options > Environment > Keyboard
Either, find "VisualD.ToggleCommentSelection" or
Search for "comment" and the bottom option should be "VisualD.ToggleCommentSelection"
- 103
- 2