What key shortcuts are to comment and uncomment code?

Visual StudioCommentsVisual Studio-2012

Visual Studio Problem Overview


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?

Visual Studio Solutions


Solution 1 - Visual Studio

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

Solution 2 - Visual Studio

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

View > Toolbars > Text Editor

enter image description here

Solution 3 - Visual Studio

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

Solution 4 - Visual Studio

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.

Solution 5 - Visual Studio

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)

Solution 6 - Visual Studio

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.

Solution 7 - Visual Studio

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

Solution 8 - Visual Studio

Shift + alt + a

the command palette is great for finding shortcut keys.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDmytroView Question on Stackoverflow
Solution 1 - Visual StudioJames McNellisView Answer on Stackoverflow
Solution 2 - Visual StudioMacGyverView Answer on Stackoverflow
Solution 3 - Visual StudioMuhammad Sibtain ArainView Answer on Stackoverflow
Solution 4 - Visual StudioRichard BanksView Answer on Stackoverflow
Solution 5 - Visual StudioCodeTantricView Answer on Stackoverflow
Solution 6 - Visual StudioChristopher AdamsView Answer on Stackoverflow
Solution 7 - Visual StudioUTF2390View Answer on Stackoverflow
Solution 8 - Visual StudioRoyer AdamesView Answer on Stackoverflow