简体   繁体   中英

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

  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.

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

If you have resharper, you can use keyboard shortcut

Ctrl+Shift+/

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

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM