Indentation of line comments’ slashes
Intellij IdeaIntellij Idea Problem Overview
When I use IntelliJ’s function “Comment with Line Comment” it places two slashes at the very beginning of the selected lines. The forward slashes are not indented with the rest of the code. How can I make IntelliJ obey the line indentation when placing the forward slashes?
Example code:
if (something) {
bar();
}
Using IntelliJ’s commenting function on line 2 results in:
if (something) {
// bar();
}
What I want:
if (something) {
// bar();
}
Intellij Idea Solutions
Solution 1 - Intellij Idea
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.
Solution 2 - Intellij Idea
Solution 3 - Intellij Idea
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
.
Solution 4 - Intellij Idea
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
Solution 5 - Intellij Idea
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.