73

I want to know how to put the /**/ comments through shortcut. I know the Ctrl+K+C shortcut for the // comments but it comments the whole line. Sometimes while debugging, I want to do something like "ref string /* char[] */ lengthValue" while trying something out.

I want to be able to comment a specific part of a line (not the whole line) through a shortcut e.g in "string /* char[] */ lengthValue" i-e comment out only a specific part of a like by shortcut

I am using Visual Studio 2013

Please help

Zia Khattak
  • 765
  • 1
  • 5
  • 8
  • 3
    Actually you can mark part of a line and then use `Ctrl+K+C` in the C++ editor. Sadly, it doesn't work like this in the C# editor. – Henrik Sep 07 '15 at 06:40
  • Tools > Options > Environment > Keyboard > Find Edit.CommentSelection – BAR Nov 29 '21 at 19:36

10 Answers10

109

Visual studio comment shortcut key: Accept in HTML, C#, JS, CSS etc in Visual studio.

Ctrl + k then Ctrl + c

//a
//b                      
//c

to undo ctrl + k then Ctrl + u

a
b
c

Ctrl + Shift + /

/*a
b
c*/

to undo Ctrl + Shift + /

a
b
c
Richard
  • 994
  • 7
  • 26
Suza
  • 1,273
  • 2
  • 9
  • 10
36

I think there is no shortcut key for this purpose in Visual Studio but If you use ReSharper you can use Ctrl + Shift + /.

Have a look at this may be useful as well.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
  • 17
    Visual Studio 2019 [now natively supports this keyboard shortcut](https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes#net-productivity) -- _Toggle Block Comment/Uncomment is now available through the keyboard shortcut (Ctrl+Shift+/) or through **Edit > Advanced > Toggle Block Comment**. This command will add or remove block comments depending on what you have selected._ – Zev Spitz Jul 03 '19 at 04:00
  • Very good, thanks. However, VS is does not uncomment multiple blocks with empty lines in between, because it doesn't comments those lines and remains unawre of that. – Jonathan Root Nov 11 '22 at 18:39
  • To toggle comment, It's `Ctrl` + `Alt` + `/` in Resharper or Rider ( with the keymap of Visual Studio ) – Pars Jun 20 '23 at 12:31
16

In Visual Studio 2017 RC, simply Select the part of code you want and then press Ctrl + K + C , no need to any extension!

Ali Rashedi
  • 195
  • 1
  • 5
11

VS 2019 I did

Tools > Options > Environment > Keyboard

Type in Edit.ToggleBlockComment and add a keybinding. I chose shft + ctrl + /

Or you could put comment in the search box of the keyboard section and look at all your comment keybinding shortcut options.

mjwrazor
  • 1,866
  • 2
  • 26
  • 42
  • Dont see any Tools tab. Where is it? – Čamo May 28 '21 at 12:02
  • @Čamo if you don't have the Tools tab somehow you customized your tabs or you have a different version of Visual Studio, not Visual Studio Code. I am talking about Visual Studio. Also you can access the same options under Debug->Options->Environment->Keyboard – mjwrazor May 28 '21 at 14:35
  • Thanks a lot. I set it to ctrl+/. – mifth Feb 08 '22 at 22:06
5

In Visual Studio Code that is called Toggle Block Comments

By default command is Shift + Alt + A

But you can customize as your own in Visual Studio Code. I did it ctrl + shift + /

Hope it might help

Mukta
  • 1,357
  • 1
  • 15
  • 17
2

To comment a block of code (more than one line) in VS select code with ALT (alt+mouse or alt+shift+arrows), and then comment with Ctrl+K Ctrl+C. With one line code only you don't need ALT.

So it's basically the same as with // comments, only ALT needs to be pressed while selecting code for more lines than one.

2

Visual Studio 2019 & 2022 support commenting a line with Ctrl + Shift + /.

You can change it by modifying Edit.ToggleBlockComment.

If you change it to Ctrl + /, you may have to remove the shortcut for EditorContextMenus.CodeWindow.GenerateDocumentationComments, which uses the same keys.

Chris Pavs
  • 85
  • 5
1

Shift + Option + A - figured it out by going to Preferences > Keyboard Shortcuts and searching "comment"

Max Hudson
  • 9,961
  • 14
  • 57
  • 107
1

Using @mjwrazor example I did a slight variation, that worked.

I was working on a Wix .wxs file and was trying to easily comment in and out like VSCode..

In VS 2022 I went to

  • Tools > Options > Environment > Keyboard

In the box "Show Commands Containing" type "Comment" and add a shortcut keys as follows:

  • Edit.CommentSelection (Fig. 1)
    • Set Global ShortCut - Ctrl + /
    • Click Assign
  • Edit.UncommentSelection
    • Set Global ShortCut - Ctrl + Shift + /## Heading ##
    • Click Assign

Job done, sigh, why does VS not just use the VSCode shortcuts.. This has been bugging me for ages, hope this helps.

Fig 1 Set Comment Fig 2 Uncomment

jcrawfor74
  • 1,613
  • 2
  • 10
  • 8
0

You can now use Ctrl + Shift + A /* for block comments */

And Ctrl + ù // for line comments