How to use tabs for indentation in IntelliJ IDEA?

How to use tabs instead of multiple spaces for indentation in IntelliJ IDEA 11.0?

I have a "Use a tab character" under Code Style> General> Default Indent Options. And also tried to check "Smart tabs", but this does not help.

In the documentation:

If this check box is selected, tabs are used:

  • When you press Tab
  • For indentation
  • To format code

Otherwise, spaces are used instead of tabs.

+119
intellij-idea indentation tabs
Dec 16 '11 at 13:26
source share
8 answers

File > Preferences > Editor > Code Style > Java > Tabs and Indents > Use Tab Character

Replace the appropriate weapon for Java.

+201
Dec 16 '11 at 1:58 p.m.
source share

IntelliJ IDEA 15

Current file only

You have the following options:

  • Ctrl + Shift + A > type "tabs"> double-click "Tabs"

    Tabs

    If you want to convert tabs to spaces, you can write “spaces” and then select “To Spaces”.

  • Edit> Convert Indentation> Tabs

    To convert tabs to spaces, you can select "To Spaces" from the same place.

For all files

The paths in the other answers have changed a bit:

  • File> Preferences ...> Editor > Code Style> Java> Tabs and Indents> Use Tab Character Use tab character
  • File> Other settings> Default settings ...> Editor > Code style> Java> Tabs and indents> Use tab character
  • File> Preferences ...> Editor > Code Style> Detecting and Using Existing File Indents for Editing
  • File> Other settings> Default settings ...> Editor > Code Style> Detecting and using existing file indentation for editing

It does not seem to matter if you check / uncheck the box from Settings ... or from Other settings> Default settings ... since a change in one window will be available in another window.

The above changes will be applied to new files , but if you want to change the spaces to tabs in an existing file , then you must format by pressing Ctrl + Alt + L.

+37
Jan 01 '15 at 20:26
source share

I started using IntelliJ IDEA Community Edition version 12.1.3 , and I found the setting in the following place: -

File > Other Settings > Default Settings > {choose from Code Style dropdown} 
+23
May 24 '13 at 11:05
source share

For those who are not able to get this, one more thing you need to take off is also

 Preferences > Editor > Code Style [] Enable EditorConfig support EditorConfig may override the IDE code style settings 

My version of IntelliJ is 15.0.4

+13
Mar 03 '16 at 9:55
source share

Another useful option in IDEA to disable or save if you really need it:

 Preferences -> Code Style -> Detect and use existing file indents for editing 

if your team switches to formatting tabs with existing code written in spaces, uncheck that

+10
Jan 23 '15 at 16:25
source share

Have you tried . editorconfig ? You can create this file in the root directory of your project and adjust the indentation for different types of files. Your code will be automatically formatted. Here is an example:

 # top-most EditorConfig file root = true # matches all files [*] indent_style = tab indent_size = 4 # only json [*.json] indent_style = space indent_size = 2 
+6
Mar 01 '17 at 23:26
source share

My version of Intellij 13.4.1

 Intellij IDEA->Perference->Code Style(Project Setting) 
0
Oct 07 '14 at 20:23
source share

To extend the answer to @Dmitiri Algazin: settings for individual languages ​​are canceled by the general setting

 Preferences -> Code Style -> Detect and use existing file indents for editing 

So, if you are wondering why your new settings are ignored after changing the settings for a specific language, there is a chance that this check box is checked.

As a side note; changing any default settings automatically creates a profile profile clone (i.e. Default(1) ), which, I believe, is set so that the default IDE settings are never overwritten.

At first it’s a bit confusing whether editing the Default settings or Project Settings really will have any effect on your project, since you can select Default from the drop-down menu and then edit from there.

If you do not want to see random default clones to populate settings profiles, edit the project settings directly.

0
Nov 07 '15 at 13:29
source share



All Articles