Line comment shifts code 2 spaces to the right (when using first column //)

Answered

I want code that is commented out with line comments to retain its position. I have this set on one computer, but I cannot find the setting anymore so I can set it on other instances of IDEA (currently running 2019 on both computers):

0
5 comments

It is needed to use smart tabs for that: 

0
Avatar
Permanently deleted user

I did notice that I did not have that turned on initially, but checking them did not fix it for me. These are my settings in IDEA code style xml format:

<codeStyleSettings language="JAVA">
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="1" />
<option name="FOR_BRACE_FORCE" value="1" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
0

May you try with a new file? 

Most probably, spaces were not converted into tabs in existing source code. 

0
Avatar
Permanently deleted user

I did have to create a new file to see the change.

0

To apply that to existing files: 

In IntelliJ IDEA, to convert existing tabs to spaces or vice versa, use File → Edit → Convert Indents → To Spaces (or To Tabs). The Reformat code shortcut CtrlAltL will also do this, while applying other changes.

From https://stackoverflow.com/a/64037470/8203759

0

Please sign in to leave a comment.