Keyboard shortcut for Visual c# block comment in Visual Studio 2015?
Asked Answered
S

6

14

I know there is keyboard shortcut for single line(//....) commenting Ctrl + K + C and uncommenting Ctrl + K + U .

My question is that, is there any default keyboard shortcut for block (/* ...... */) commenting and uncommenting? If yes how?

And If there is no default block commenting keyboard shortcut defined, So is there a way i could add my own keyboard shortcut for this? How do i do that?

I have found lot of questions regarding commenting, but haven't found spoken about block commenting anywhere. Any help is appreciated :)

Swept answered 16/9, 2015 at 13:30 Comment(5)
Pretty sure there isn't. All you can do is highlight multiple lines and do Ctrl K + C / K + U as you mentioned. This will at least comment all of the selected lines. So it's similar behavior. I haven't yet used VS 2015, actually, but every other version works this way. Don't know about adding your own shortcut, unfortunately.Stint
is there a way i could add a shortcut to do block commenting?Swept
I know you can add custom shortcuts to existing behavior, but I don't think you can create new shortcuts with new behavior. You'd have to create a macro and bind that macro to a key, or drop a button for it on a toolbar somewhere. Not sure how you'd do this though, I scarcely use VS Macros.Stint
Related: #31859968Stop
There are numerous reasons why the style of comment with /* */ are not recommended: - they cannot be placed inside one another, they can be mistaken in some cases by compilers as regular expressions.Deluxe
A
11

for me, in Visual Studio 2015 community edition, when I select full lines it will insert // comments. If I select the lines only partially (the first line is not selected from the very beginning or the last line is not selected till the end), it will insert /* comments. The shortcut is the same, Ctrl + K + C.

Full lines selected:
These lines will be commented with //

Press Ctrl + K + C

Result:

//These lines will //be commented with //

Partial lines selected:
These lines will be commented with /*

Press Ctrl + K + C

Result:

These /*lines will be commented*/ with /*

Aurist answered 9/1, 2016 at 22:23 Comment(3)
Is this really working? Or this /*.....*/ is limited to community version only? I have used VS 2000, 2015 & 2017 Professional version, but neither of them supports the block comment.Martres
I just tested again and the behavior changed a little in VS Community v. 15.5.2: It will add /* only if you select partially one line. Otherwise it will add //.Aurist
In latest version of Visual Studio Code (Version: 1.29.1 (user setup)), ctrl+k+u is not working but ctrl+k+c only works like //be commented with // -- irrespective of selecting single or multi-line.Salutary
L
7
  1. I used FeinCtrl to list all available commands, and there are only two related to commenting code in/out: Edit.CommentSelection and Edit.UncommentSelection; there are no other commands that could do a block commenting.

  2. You can add your own shortcuts to any EXISTING command by going into Tools -> Options -> Environment -> Keyboard, selecting a command and assigning your new key combination.

  3. If you search this site, you'll find a lot of reasons to NOT use block comments at all.

Lathery answered 16/9, 2015 at 13:43 Comment(0)
M
6

If you have resharper, you can use keyboard shortcut

Ctrl+Shift+/

to put block comment around selected statements. I hope this helps.

Maley answered 9/9, 2016 at 6:43 Comment(1)
Just what I needed! It's worth noting that this acts as a toggle, so selecting the same text and repeating the keystrokes removes the comment.Mopboard
O
5

You can use three /// to create...

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Orose answered 22/12, 2017 at 15:52 Comment(0)
F
2

For a simple block comment you can create the following C# command in Visual Commander and assign a shortcut to it:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
        EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
        ts.Text = "/* " + ts.Text + " */";
}
Fro answered 22/9, 2015 at 13:55 Comment(0)
S
0

In latest version of Visual Studio Code (Version : 1.29.1(user setup)), you can try Ctrl+/ for single line comment & Shift+Alt+A for block comment. If you can click on edit of your menu bar, there you should be able to find the necessary info.

Salutary answered 17/12, 2018 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.