I have installed google-java-format
plugin for IntelliJ
and I have enabled the plugin. When I format the code, my java code gets indented by 2 spaces. How do i change the google java formatter plugin setting to change to 4 spaces?
To toggle between tabs and spaces: On the main menu, choose Edit → Convert Indents, and then choose To Spaces or To Tabs respectively.
Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. Select the Detect and use existing file indents for editing checkbox. Apply the changes and close the dialog.
If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.
The braces used in Java follows the Kernighan and Ritchie style (K & R Style) to indent non-empty blocks and blocks like construct. No line break before the opening brace. Line break after the opening brace. Line break before the closing brace.
First I disabled the IntelliJ
google-java-format plugin.Downloaded IntelliJ-java-google-style.xml
from here and modified indent size property as below. After importing this style in IntelliJ, I am able to indent to 4 spaces. To import the code style XML, please refer to this link
<codeStyleSettings language="CSS">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
I was able to change to 4-space indentations by selecting the Android Open Source Project (AOSP) style in the google-java-format plugin settings:
It looks like the only difference between the two styles is that AOSP doubles the spacing to 4 instead of 2: https://github.com/google/google-java-format/blob/master/core/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java#L37
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With