Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij: add space after double slashes in line comment

Is there a way in Intellij IDEA (I'm using version 13) to automatically add a space to line comments between the two slashes and the text:

If I enter :

//This is a comment

I'd like to get the following when I run a code reformat (Ctrl-Alt-L on Windows)

// This is a comment

It's for Javascript files but should be working for other file types.

like image 547
Nicolas Forney Avatar asked Jul 19 '14 12:07

Nicolas Forney


People also ask

How do I comment multiple lines in IntelliJ?

To quickly add a line comment in IntelliJ IDEA, press ⌘ / on macOS or Ctrl + / on Windows and Linux. Block comments or multi-line comments usually take the form of a paragraph.

How do I add automatic comments in IntelliJ?

Type /** 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 comment out a block of code in IntelliJ?

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


1 Answers

If you press CTRL / or CMD / it will put // at the beginning of the line and the comment will be properly indented.

//        comment with two indents 

For this to work Comment at first column must be checked in Editor->CodeStyle->Javascript->Wrapping and Braces->Keep when reformatting like mentioned in another answer.

screenshot This screenshot is for Java, but it works the same for Javascript. Just choose javascript in the menu

If you want to write multiline comment you can use CTRL SHIFT / or CMD SHIFT / That way when you go into new line, you will have one space after the comment start

    /*     * there is space before this*/ 
like image 184
Tree Avatar answered Sep 17 '22 10:09

Tree