aimme
aimme

Reputation: 6763

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

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 :)

Upvotes: 14

Views: 35665

Answers (6)

whoami - fakeFaceTrueSoul
whoami - fakeFaceTrueSoul

Reputation: 17915

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.

Upvotes: 0

Cliff
Cliff

Reputation: 51

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

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

Upvotes: 5

GoTo
GoTo

Reputation: 6666

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 /*

Upvotes: 11

MKMohanty
MKMohanty

Reputation: 966

If you have resharper, you can use keyboard shortcut

Ctrl+Shift+/

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

Upvotes: 6

Sergey Vlasov
Sergey Vlasov

Reputation: 27880

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 + " */";
}

Upvotes: 2

Vlad Feinstein
Vlad Feinstein

Reputation: 11311

  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.

Upvotes: 7

Related Questions