How can I use tabs for indentation in IntelliJ IDEA?

前端 未结 9 1592
小蘑菇
小蘑菇 2021-01-30 09:35

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

I have \"Use tab character\" checked under \"Code Style\" > \"General\" > \

相关标签:
9条回答
  • 2021-01-30 10:18

    IntelliJ IDEA 15

    Only for the current file

    You have the following options:

    1. Ctrl + Shift + A > write "tabs" > double click on "To Tabs"

      If you want to convert tabs to spaces, you can write "spaces", then choose "To Spaces".

    2. Edit > Convert Indents > To Tabs

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

    For all files

    The paths in the other answers were changed a little:

    • File > Settings... > Editor > Code Style > Java > Tabs and Indents > Use tab character
    • File > Other Settings > Default Settings... > Editor > Code Style > Java > Tabs and Indents > Use tab character
    • File > Settings... > Editor > Code Style > Detect and use existing file indents for editing
    • File > Other Settings > Default Settings... > Editor > Code Style > Detect and use existing file indents for editing

    It seems that it doesn't matter if you check/uncheck the box from Settings... or from Other Settings > Default Settings..., because the change from one window will be available in the other window.

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

    0 讨论(0)
  • 2021-01-30 10:18

    My Intellij version is 13.4.1

    Intellij IDEA->Perference->Code Style(Project Setting)
    
    0 讨论(0)
  • 2021-01-30 10:18

    For those who are having trouble indenting phpstorm here I have a tip and I hope they help ...

    First you have to go to file-> settings-> keymap-> select-> windows.

    If they are on the windows machine. If you are on mac and choose macos.

    0 讨论(0)
  • 2021-01-30 10:21

    To expand on @Dmitiri Algazin 's answer: settings for individual languages are overridden 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 being ignored after changing your settings for a specific language, there is a chance this checkbox is ticked.

    As a side note; changing any default settings automamagically creates a settings profile clone (i.e. Default(1)) which I assume is in place so that the default IDE settings are never overwritten.

    It is a little confusing at first, really, whether editing Default settings or Project Settings is going to have any effect on your project, since you can select Default from the drop down menu and then edit from there.

    If you don't want to keep seeing random clones of Default populating your settings profiles, edit the Project Settings directly.

    0 讨论(0)
  • 2021-01-30 10:22

    Another useful option in IDEA to switch off or keep checked if you really need that:

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

    if your team is going to switch to tab formatting with existing code written with spaces, uncheck that

    0 讨论(0)
  • 2021-01-30 10:26

    For anyone not able to get this, another thing you need to uncheck the following as well

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

    My IntelliJ version 15.0.4

    0 讨论(0)
提交回复
热议问题