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.

有帮助吗?

解决方案

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top