Da DUAN
Da DUAN

Reputation: 552

Intellij comment format

Now, I am using the default configurations, and the "//" is displayed at the first column when I press the "command" + "/", see the second line in the picture.

How can I change configuration to display the "//" at the start of the code and following with a space? Just like the first line.

enter image description here

Upvotes: 44

Views: 14476

Answers (3)

gachokaeric
gachokaeric

Reputation: 110

To fix comments during reformatting, go to file->settings->editor->code style->java->wrapping and braces->keep when reformatting->uncheck "comment at first column"

enter image description here

Upvotes: 0

igr
igr

Reputation: 10634

There is an option in: Code Style > Java > Code Generation > Comment Code

intellij cfg

With "Line comment at first column" you can switch between:

    //System.out.println("");
//  System.out.println("");

So, you don't have a 'space' after comment (in first line), but its close enough :)

Idea 2017.2+

Recent versions of IntelliJ IDEA support adding a space after the line comment. The setting is at the same location.

enter image description here

Upvotes: 72

user1445967
user1445967

Reputation: 1570

IntelliJ 2017.2 now does exactly what you want. I'm not sure when this was originally introduced.

Project Settings > Code Style > Java
Change tab to Code Generation, locate Comment Code section
Uncheck "Line Comment at First Column"
Check "Add a space at comment start"

Now when you press Control-/

    boolean goodCode = true;

becomes

    // boolean goodCode = true;

Upvotes: 1

Related Questions