Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent IntelliJ to stop continuing double-slash comments on the next line?

Short version

When pressing <enter> at the end of a // comment, Intellij sometimes decides to continue the // comment on the next line. How can I prevent that? Is there a setting somewhere to disable this automation?

Long version

There is a thing I do regularily, it is to break a long expression with a double-slash.

Let's say I have a line like

boolean isHex = c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f';

and I want to split it like that

boolean isHex = c >= '0' && c <= '9' //
        || c >= 'A' && c <= 'F' //
        || c >= 'a' && c <= 'f';

Note that I want the final // in order to prevent any formatter to join the lines again.

So I insert a double-slash-return after the '9', by pressing //<enter>. But Intellij will auto-continue the comment on the next line.

boolean isHex = c >= '0' && c <= '9' //
// || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f';

It forces me to uncomment and reindent the line manually.

I want Intellij to not continue the comment on the next line and optionally indent my code:

boolean isHex = c >= '0' && c <= '9' //
        || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f';

So I want to disable this "continue // comment after <enter>" feature. Is it possible? I haven't found any setting related to that.

like image 757
Florian F Avatar asked Jul 20 '17 19:07

Florian F


People also ask

How to remove commented code in IntelliJ?

To add or remove a block comment, do one of the following: From the main menu, select Code | Comment with Block Comment. Press Ctrl+Shift+/ .


1 Answers

The closest you are going to get is to define a macro to insert a new line and remove the comment and then bind that macro to a suitable key.

like image 64
matt helliwell Avatar answered Oct 10 '22 14:10

matt helliwell