Change ctrl k+c to produce c style comment (/**/)

2020-04-18 04:11发布

问题:

How do i change the comment style used in visual studio from // to /*...*/ ?

I use the comment shortcut mostly for commenting out code temporarily.

It annoys me that if i select bool abc in the code below and press ctrl k+c

void func( bool abc ) {}

it produces

//void func( bool abc ) {}

instead of

void func( /*bool abc*/ ) {}

Regards

Henrik

回答1:

You can do it with a macro. Make it look like this:

Public Sub CommentSelection()
    If Not DTE.ActiveDocument.Selection.IsEmpty Then
        DTE.ActiveDocument.Selection.Text = "/* " + DTE.ActiveDocument.Selection.Text + " */"
    End If
End Sub

Bind it to a key other than Ctrl-K+C, you'll want to keep that one around.



回答2:

ReSharper does this CTRL + SHIFT + C

Otherwise, a macro would be your best bet, add this to your VS Macros and bind it to a keyboard shortcut of your choosing:

edit: removed my crappy code, nobugz beat me.