Reputation: 121
Sometimes I have the need to try: A code example or a variant of it.
This is necessary to test a new functionality or to test its implementation or performance.
The code can be very long.
So I need some way to quickly comment on the code with
/*
* mi código
* …
* /
O con:
//
// mi código
// …
//
When the code is very long, it is cumbersome to do: Select all the code you do not want to run and discuss, Write or insert the code you want to try, Do tests or whatever...
Now...
Select and comment on the new block of code.
Search and select the previous code, and Uncomment.
Do tests or whatever...
And so I need to do it many times since I'm recycling, as I have been thirty years since I program almost nothing.
Is There any way or trick to do it quickly?
Upvotes: 10
Views: 67250
Reputation: 1
If you know what block of code you want to switch on and off, and it's more or less a large one, here is a handy trick to handle this:
//*
// [Large block of code - ACTIVE]
//*/
To switch it on (i.e. comment it out in the fancier way to say it), just remove the backslash at the beginning of the very first line, like so:
/*
// [Large block of code - now INACTIVE/commented out]
//*/
Hope that helps.
Upvotes: 0
Reputation: 11
if u want comment in VS code select the entire line of comment which you want and click on **ctrl+ / ** It is used for all types of languages
Upvotes: 1
Reputation: 1676
In Visual Studio 2019 Preview
Comment : Ctrl + k and Ctrl + c
Uncomment : Ctrl + k and Ctrl + u
Upvotes: 8
Reputation: 21
Upvotes: 2
Reputation: 833
If you are using visual studio as your IDE you can use the following:
Ctrl+K+C
to commment and Ctrl+K+U
to uncomment.
If using pycharm or VS Code:
Use Cntrl+/
to comment and uncomment.
Upvotes: 15
Reputation: 121
Trick:
When We have a very long code and need to comment and uncomment quickly:
ADD at the beginning of the BLOCK:
/*//TODO: Comment or uncomment this block.
Remove an inclined bar at the beginning of the line to uncomment.
Add an inclined bar at the beginning of the line to comment. '
And add at the end of the block
/*/
The tag TODO: It shows you in tasks the message,
so you can locate it quickly.
In Addition the commented code can collapse in the [+] when it is commented.
Commented Code:
[+]/*//TODO: Add a "/" at startup to uncomment.
This block does something.
...
Code 100000.0 lines.
...
/*/
Uncommented Code:
//*//TODO: Remove a "/" at startup to comment.
This block does something.
[+] ...
Code 100000.0 lines.
...
/*/
I Didn't know how to tell everybody, like I do.
I Hope it's useful.
Upvotes: -1
Reputation: 2052
If you're in vs code just enter ctrl + /. For VS studio 2017 ctrl + k + u.
Upvotes: 6