Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 501
Da DUAN Avatar asked Sep 16 '13 06:09

Da DUAN


People also ask

How do I comment in IntelliJ?

Comment and uncomment blocks of codeFrom the main menu, select Code | Comment with Block Comment. Press Ctrl+Shift+/ .

How do I wrap comments in IntelliJ?

You can enable soft wrap for the editor with ⇧⇧ (macOS), or *Shift+Shift (Windows/Linux), for the Search Everywhere dialogue, and then typing in soft wrap. You can also go to Preferences/Settings > Editor > General to enable Soft Wraps for more file types by default.

How do I set default comments in IntelliJ?

Add a new commentType /** before a declaration and press Enter . The IDE auto-completes the doc comment for you. For information on how to disable this feature, refer to Disable automatic comments.

How do I fix format in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.


2 Answers

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

like image 192
igr Avatar answered Sep 26 '22 02:09

igr


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; 
like image 31
user1445967 Avatar answered Sep 22 '22 02:09

user1445967