Question

If I have some JavaScript code that I want to comment out like:

{
    // Inside some scope
    var foo = "bar";
    foo += "bar";
}

I expect to have the following after commenting out the code

{
    /*
    // Inside some scope
    var foo = "bar";
    foo += "bar";
    */
}

But, instead I'll get something like the following, which I have to reindent:

{
    /*
    // Inside some scope
    var foo = "bar";
    foo += "bar";
*/
}

I want to know if there's a preference to prevent this from happening.

Was it helpful?

Solution

Highlight the code you want to comment out, and press ctrl + / - this will comment out the code without any indenting issues and is is easily reversible. The other advantage of this strategy is it works across most languages (including HTML).

Alternatively, you could use ctrl + shift + / to use multiline comments, as rlemon mentions in the comments. (usually I'm too lazy)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top