行注释斜杠的缩进

当我使用 IntelliJ 的函数“用行注释注释”时,它会在所选行的开头放置两个斜杠。正斜杠不与代码的其余部分缩进。如何使 IntelliJ 在放置正斜杠时遵守行缩进?

示例代码:

if (something) {
bar();
}

在第2行使用 IntelliJ 的评论功能,结果是:

if (something) {
//  bar();
}

我想要的:

if (something) {
// bar();
}
9364 次浏览

Go to File > Settings > Editor > Code Style > Java > Code Generation and uncheck the option "Line comment at first column".

Update Oct 2016 from @henrebotha in the comments:

As of now, there's an additional option just beneath it that says "Add a space at comment start", so this is now supported.

You can setup in Code Generation: Options

In more recent versions the setting is called: Comment at first column

Just search for it in the settings window, then go to Editor -> Code Style -> Your language.

For those who are looking on how to do this for Scala, the Line comment at first column configuration is in File > Settings > Editor > Code Style > Scala > Other tab instead of Code Generation as with the accepted answer

Just in case you are feeling my pain, in a shared code style environment this might not work for you if Settings > Editor > Code Style > Enable EditorConfig support is checked.

It may well be overridden in your shared style. You are going to have to talk to your project fashion police about that.