How can I configure removing space between line comment slasles and text in Intellij IDEA?

Viewed 624

If I want to comment line I use "Ctrl+/" and get the "//" at start of line

enter image description here

Then I use auto formatting with "Ctrl+alt+L" keys and get

enter image description here

At the end I must remove space between "//" and text manually every time...

enter code here

Can I do all of these steps in one time? I didn't find any settings for this...

3 Answers

I suggest you can use a setting to avoid the further indentation of your comment (the effect of the second screenshot).

Your comments will look like this:

//        Bundle b = new Bundle();

That might not be quite exactly what you want, but at least you will be able to use "Ctrl+/" after the reformatting to return the line to a properly aligned state.

Here is the setting:

  1. Go to Settings -> Project Settings -> Code Style -> Java

  2. On the Wrapping and Braces tab, find the tree item at the top: Keep when reformatting and tick: Comment at first column

This works for Scala.

Preferences -> Editor -> Code Style -> Scala -> Other -> Comment Code

Uncheck Line comment at first column and Block comment at first column.


Example:

def regexTest(): Unit = {
    Comment

When press comment shortcut in line 2, the above code becomes

def regexTest(): Unit = {
    //Comment

Version 2020.2

Related