How to uncomment multiple lines of code in Visual Studio
Asked Answered
P

17

70

I did a ctrl K + ctrl C (adds // to a line) on a lot of lines of code that I need uncommented. What is the quick key method to uncomment code in Visual studio?

Pacifica answered 19/4, 2011 at 14:18 Comment(2)
When in doubt, check the menu item itself. The keyboard shortcuts are listed in the right margin.Pinero
Is there an uncommenting solution when commenting shorthand is used? I used "/* ... */" and VS 2019 automatically adding a "*"to each new line created in the section. Sadly, not a single one of the options below or the Right Click menu seem able to quickly uncomment this section. Obviously, deleting the first and last comment block characters didn't work either.Abixah
C
116

Ctrl+K, Ctrl+U removes the // comments

Caen answered 19/4, 2011 at 14:21 Comment(2)
CTRL K + C adds the comments backLanthanum
In my Visual Code Ctrl + C, add comments Ctrl + C again, remove comentsWaits
B
26

I believe it is Ctrl + K, Ctrl + U.

Bench answered 19/4, 2011 at 14:20 Comment(0)
P
7

Ctrl + K, Ctrl + U.

There is also a button for it on the Standard toolbar.

Plasticine answered 19/4, 2011 at 14:20 Comment(0)
D
5

ctrl + / can be used for adding and removing comments.

Doggy answered 25/8, 2021 at 23:11 Comment(0)
I
3

Try + U or click the little icon on the toolbar.

Irascible answered 19/4, 2011 at 14:28 Comment(0)
C
3

If you're using Resharper, there is a much nicer alternative:

just right Alt + / for both

By using this single shortcut, you can simply toggle between commenting/uncommenting code, without having to remember/switch between two shortcuts for each.

Crocodilian answered 7/12, 2016 at 14:39 Comment(0)
J
3

Ctrl + K + C (to comment) and Ctrl + k + U (to uncomment the code)

Or

or use Ctrl + / (for the same)

Jacintajacinth answered 19/6, 2020 at 9:43 Comment(0)
C
2

Qwerty: Ctrl + /

Azerty: Ctrl + :

Cassius answered 14/4, 2020 at 13:47 Comment(2)
This comments, but won't uncomment.Unmeet
it does both for meCohesive
M
1

Just wanted to add, that in the latest version of VS, ctrl + u makes it caps. They instead made it a toggle command, so it is actually just ctrl + k again to make it uncommented.

Muse answered 28/6, 2018 at 14:40 Comment(0)
D
1

I have the german keyboardlayout. VSCode-x64-1.52.1 To leave a comment: You have to highlight the code, then push Ctrl + # or Ctrl+K, stay at Ctrl and push C

to commen out: Ctrl + #, it toggles on/off the comment or Ctrl + K, stay at Ctrl and push U

Diatonic answered 6/1, 2021 at 13:33 Comment(0)
P
0

Mine was a bit different. It is ctrl-shift-C to comment and ctrl-shift-alt-C to uncomment.

I am using Visual Studio Community 2017.

Phares answered 10/4, 2018 at 23:0 Comment(2)
Are you sure you're using the default settings? I am also using VS Community 2017, but that shortcut opens the class view window for me. And code commenting is accomplished through the same method that the OP uses.Ova
As far as I know I am using the default settings. I haven't changed any macros. I am using it to developer for Unity so perhaps the Unity plugin changed the default settings? Not sure why that would be though.Phares
C
0

Ctrl + Q alternates between comment and uncomment. Unfortunately Ctrl K Ctrl U does not work in few environments, rather it adds instead of removing. My case on windows, using composer file I faced Ctrl K Ctrl U not working. I m using VS Code, ver 1.36.1

links to all keys short cuts: https://code.visualstudio.com/docs/getstarted/keybindings

Catabasis answered 6/8, 2019 at 18:35 Comment(0)
K
0

In Visual C++ 2019 Ctrl + Shift + / both comments and uncomments.

Killarney answered 27/7, 2020 at 3:14 Comment(0)
D
0

italian keyboard uncomment: Ctrl + ù

Debonair answered 22/7, 2023 at 12:19 Comment(0)
C
0

On MacOS you can Command + / to comment and uncomment.

Counterstatement answered 13/6 at 23:50 Comment(0)
F
0

You can't use any of those key combinations as all the answers do not work in vs2022.

Not a single one, all the answers are useless wranglings.

These answers are simply comical!

ok, one works cntrl-k, then type cntrl-c.

to uncomment Ctrl + K then Ctrl + U. press K then C or U while holding down control.

But there is another couple of ways In VS2022 select View > Toolbars > Text Editor.

This toolbar has a comment and uncomment button on it. You can highlight as much of your code as you want and then press the comment button and it will comment it all out at once, and vice versa for uncomment.

You can collapse a sub, like press arror on left by line numbers Then highlight the entire collapsed code stub, and click the comment button on your toolbar. There's also an uncomment button that you can use to uncomment a sub or a block of commented code...

Florid answered 17/7 at 11:44 Comment(0)
G
-1

Windows: Shift+Alt+A is a toggle. Simply choose your lines of code you want to comment out then Shift+Alt+A, then simply choose your lines of code you want uncomment and then Shift+Alt+A.

Genitalia answered 30/8, 2023 at 23:53 Comment(1)
Shift+Alt+A toggles comments in Visual Studio Code, not in Visual Studio. These two are completely different applications.Cavy

© 2022 - 2024 — McMap. All rights reserved.