62

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.

Riwaz Poudyal
  • 855
  • 1
  • 8
  • 15
  • 1
    Highlight one file project with the 4 spaces included. Press Ctrl+F4 to bring the Find and Replace text box. Copy and paste the file (without the spaces) to the Replace text box. Then press Replace or Replace next :) – Auguste Jun 10 '16 at 17:45
  • 1
    Similar question with an approved answer: http://stackoverflow.com/questions/27926762/intellij-indents-4-spaces-when-i-have-configured-it-to-do-2-spaces-less – ezPaint Jun 10 '16 at 17:48

1 Answers1

102

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.

James Tanner
  • 1,542
  • 1
  • 11
  • 10
  • Code style does not have specific language option or the amount of indentation. – Riwaz Poudyal Jun 10 '16 at 18:10
  • Edited my answer to add a picture showing the options tree as well as the options you're looking for. If yours doesn't look like this, then you'll need to tell us what version of IDEA you have. – James Tanner Jun 10 '16 at 18:34
  • 7
    Good to know about EditorConfig! Thanks @JamesTanner – Victor Jun 10 '16 at 18:40
  • 1
    @JamesTanner I would also note that Ctrl + Shift + A on Windows allows you to search for anything. If you search for indent, it will have the same effect as your statement about searching for indent in the Settings window. – Cache Staheli Jun 10 '16 at 19:51
  • 2
    @CacheStaheli, quite true. However, I find keyboard shortcuts provide for unreliable instructions, since IDEA includes no fewer than three different sets of them you can choose out of the box. (Varying by both operating system and which other IDE you would like to pretend you are using.) – James Tanner Jun 10 '16 at 19:54
  • the question was about "change project indent" not "IDE settings". for example, I can have 2 projects with 2 spaces indent and 4 spaces indent. downvote – Alexey Sh. Sep 12 '18 at 15:24
  • You may have to also uncheck "Smart Indent" in the "Smart Keys" tab. – sdexp Sep 13 '18 at 15:05
  • @AlexeySh. By default, IDEA stores settings on a per-project basis. So changing this setting changes it for that particular project, not the entire IDE. – James Tanner Sep 13 '18 at 16:13
  • This applied changes to only that specific file. How to apply the changes to existing files in other folder of the project? – Murtaza Haji Nov 24 '20 at 17:39