How do I apply comments at the indent level when toggling them?

When toggling a comment in a PHP document using Code > Comment with Line Comment or pressing Command + /, PhpStorm behaves by:

1. Adding a double forward slash at line position 1 and;
2. Moving the cursor to the next line.

e.g. Result after commenting line 44:

Screenshot on 2013-05-24 at 21.48.25.png

Is there any way I can change this behaviour to:

1. Add a comment at the current indent level and;
2. Leave the cursor where it is?

e.g. I'd prefer if this was the result after commenting line 44:

Screenshot on 2013-05-24 at 21.49.58.png

11

@Manoj

Comment indentation for PHP has been fixed 4 years ago, there is an option for that. Similar option exists for JavaScript as well.

19

Came here while searching for the same functionality.
I prefer it apply comments right before the first line too.
Now I have to write my comments, hit cmd+/ and *ugh....go back and correct the indentation.
Please make it smarter soon.
Thanks.

5

Its really frustrating to always correct the indentation of comment. I am surprised how Intellij doesn't have this yet since almost all good editors(Sublime) have it. 

+1 for "Please make it smarter soon" :)

2

@Andriy - Thanks for sharing, yes its available. I recently started using Intellij, doesn't know much about options. I am using Scala and not having options for "Add a space at comment start" , is there a ways to set it for Scala? 

1

Code formatting is implemented separately for each language. If Scala does not have such option, then it's not yet implemented.

https://youtrack.jetbrains.com/issue/SCL-10125 perhaps? If not -- feel free to create your own ticket: https://youtrack.jetbrains.com/issues/SCL

1

Hi there,

Is there any way I can change this behaviour to:

No.

Currently you can: invoke "Code | Reformat Code..." on a selection later .. and with appropriate setting (Settings | Code Style | PHP) it will move comment to the same indent level.

I'm not going to comment on what is the correct indent level should be (I personally prefer current behaviour) .. but moving cursor to next line is very logical action as this what is done in vast majority of comment line usage cases.

In any case: http://youtrack.jetbrains.com/issue/WI-14262 (for PHP) and http://youtrack.jetbrains.com/issue/WEB-2189 (for JavaScript)

0

Many thanks for this. I've upvoted the two filed feature requests and will try to get used to the cursor behaviour. (I've moved to PhpStorm from Sublime Text, which leaves the cursor on the same line when toggling a comment.)

0

Is there the same option for DataGrip?

0

These 2 are only available options to control comments in SQL:

File | Settings | Editor | Code Style | SQL | General -> Queries -> Align comments...

File | Settings | Editor | Code Style | SQL | General -> Wrapping -> Comments at first column

feel free to create feature request here https://youtrack.jetbrains.com/issues/DBE

0

You can also do this in Java at:

File > Settings > Editor > Code Style > Java > Code Generation

See: https://stackoverflow.com/questions/32342682/indentation-of-line-comments-slashes

0

Weird this still hasn't been fixed, coming from VS Code I find this very odd and very annoying.

0

Beatrix Ducz

Weird this still hasn't been fixed, coming from VS Code I find this very odd and very annoying.

What exactly does not work and where? Try to be a little bit specific please: some context and a code sample perhaps?

0

Andriy Bazanov

Adding a comment puts the slashes in the first column not where the indentation from the previous line starts, and there are no settings to be found for this. (see title of topic)

0

Beatrix Ducz

Adding a comment puts the slashes in the first column not where the indentation from the previous line starts, and there are no settings to be found for this. (see title of topic)

For which language?

I'm asking because it works fine for PHP / such an option exists for about 8 years now (just check my previous comments)

0

请先登录再写评论。