Skip to content

Java/IntelliJ: shortcut to insert comment directly next to code instead of at start of line [macOS]

When I use the default commenting shortcut in IntelliJ (cmd + /) it inserts the // comment line at the first position of the line like so:

no comment

Coming from vscode / javascript, I’m used to the commenting shortcut tucking the comment in directly to the left of the text of a line, preserving the indents:

enter image description here

Is there a way to modify the IntelliJ shortcut so that it comments the line of code using the format from the second example, rather than the first?

Answer

Go to Preferences | Editor | Code Style | Java > Code Generation and untick “Line Comment at first column” checkbox: