Search code examples
intellij-ideaindentation

How can I use tabs for indentation in IntelliJ IDEA?


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" > "Default Indent Options". And also tried to have "Smart tabs" checked, but it doesn't help.

From the documentation:

If this check box is selected, tab characters are used:

  • On pressing the Tab key
  • For indentation
  • For code reformatting

Otherwise, spaces are used instead of tabs.


Solution

  • IntelliJ IDEA 15

    Only for the current file

    You have the following options:

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

      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 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.