Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij: Change project indent from 4 spaces to 2 spaces

Currently, all of my project files are indented with 4 spaces. I want to change that to 2 spaces as my organization uses 2 as an standard, but can't find any answers.

like image 987
Riwaz Poudyal Avatar asked Jun 10 '16 17:06

Riwaz Poudyal


People also ask

How do I change the indent spacing in IntelliJ?

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.

How do I change tabs to two spaces in IntelliJ?

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 Ctrl + Alt + L will also do this, while applying other changes.

How do I turn off auto indent in IntelliJ?

In Preferences > Editor > Code style > [language] uncheck reformat on file save .

What is a two space indent?

If you represent the indents using space characters (ASCII SP), then 2 spaces is 2 characters fewer than 4 spaces. If you allow TAB characters to be used, then (on Windows) a TAB indents by up to 4 spaces, so TAB characters result in fewer characters.


1 Answers

Depending on your version of IDEA, it should be in your settings under:
Editor > Code Style > (Specific language)

**Edit: Example, in IDEA 2016: enter image description here

If you don't see it there, I found mine by searching "indent" in the settings window.

Finally, for organization-wide code settings, I highly recommend EditorConfig. It's compatible with just about every IDE out there and lets you enforce code style settings without requiring everyone to manually change their settings to match. IDEA supports it out of the box, without a plugin.

like image 144
James Tanner Avatar answered Sep 17 '22 11:09

James Tanner