139

There were Ctrl+E+C (comment) and Ctrl+E+U (uncomment) in older versions, or Ctrl+K+C and Ctrl+K+U.

But in VS 2012, I can't see key shortcuts:

enter image description here

How to enable those shortcuts?

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Dmytro
  • 16,668
  • 27
  • 80
  • 130

8 Answers8

167

Keyboard accelerators are configurable. You can find out which keyboard accelerators are bound to a command in Tools -> Options on the Environment -> Keyboard page.

These commands are named Edit.CommentSelection and Edit.UncommentSelection.

(With my settings, these are bound to Ctrl+K, Ctrl+C and Ctrl+K, Ctrl+U. I would guess that these are the defaults, at least in the C++ defaults, but I don't know for sure. The best way to find out is to check your settings.)

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
James McNellis
  • 348,265
  • 75
  • 913
  • 977
18

You can also add the toolbar in Visual Studio to have the buttons available.

View > Toolbars > Text Editor

enter image description here

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
  • 2
    I believe it is View -> Toolbars -> XML Editor if you are on an XML file, and then View -> Toolbars -> Text Editor if you are on a text file. If you set one, it seems to remember it for both (so you should only have to set one). – user1477388 Aug 04 '14 at 20:27
11

Use the keys CtrlK,C to comment out the line and CtrlK,U to uncomment the line.

intcreator
  • 4,206
  • 4
  • 21
  • 39
8

From your screenshot it appears you have ReSharper installed.

Depending on the key binding options you chose when you installed it, some of your standard shortcuts may now be redirected to ReSharper commands. It's worth checking, for example Ctrl+E, C is used by R# for the code cleanup dialog.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richard Banks
  • 12,456
  • 3
  • 46
  • 62
2

This is how I did it,

Menu ToolsOptions on the EnvironmentKeyboard window

One can alter the default shortcuts following the below steps

  • Select Edit.CommentSelection in the listbox
  • Click on "Remove" button
  • Select "Text Editor" option in the dropdown under "Use new shortcut in:"
  • Press your own shortcut in the textbox under "Press shortcut keys:" Example: Pressing Ctrl+E and then C will give you Ctrl+E, C
  • Click on "Assign" button
  • Repeat the same for Edit.UnCommentSelection (Ctrl+E, U)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CodeTantric
  • 120
  • 1
  • 12
1

I went to menu: ToolsOptions.

EnvironmentKeyboard.

Show command containing and searched: comment

I changed Edit.CommentSelection and assigned Ctrl+/ for commenting.

And I left Ctrl+K then U for the Edit.UncommentSelection.

These could be tweaked to the user's preference as to what key they would prefer for commenting/uncommenting.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Christopher Adams
  • 1,240
  • 10
  • 14
0

"commentLine" is the name of function you are looking for. This function coment and uncoment with the same keybinding

0

Shift + alt + a

the command palette is great for finding shortcut keys.

Royer Adames
  • 868
  • 9
  • 13
  • Command palette? That would normally [suggest](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code), not [Visual Studio](https://en.wikipedia.org/wiki/Visual_Studio) (they are two completely different things; thanks, Microsoft marketing). This question is about ***Visual Studio***. If not Visual Studio Code, what version of Visual Studio? On what version of Windows? – Peter Mortensen Jul 19 '23 at 13:44