How to quickly Comment and uncomment a code?

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

Answers (7)

Haritha Diraneyya
Haritha Diraneyya

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

Malik
Malik

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

Ray
Ray

Reputation: 1676

In Visual Studio 2019 Preview

Comment : Ctrl + k and Ctrl + c

Uncomment : Ctrl + k and Ctrl + u

Upvotes: 8

Yuri Njathi
Yuri Njathi

Reputation: 21

  1. You can select all lines in the code cell with Ctrl+A (Windows/Linux) or Cmd+A (Mac)
  2. Then press Ctrl+/ (Windows/Linux) or Cmd+/ (Mac) to uncomment
  3. Press / again to comment

Upvotes: 2

Jayant Rajwani
Jayant Rajwani

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

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

Evan Gertis
Evan Gertis

Reputation: 2052

If you're in vs code just enter ctrl + /. For VS studio 2017 ctrl + k + u.

Upvotes: 6

Related Questions