Maksym Kartsev
Maksym Kartsev

Reputation: 183

How to disable auto changing tabs to spaces in the code in Intellij Idea?

How to disable auto changing tabs to spaces and removing empty lines, whitespaces in the sourcefiles after it opened?

In other words if the line contains tabs and spaces in one line Idea shouldn't change them. For example if file contains "-->-->....-->public void setAttribute();" Idea shouldn't change tabs to spaces or spaces to tabs. I can disable all autoformattig.

Upvotes: 12

Views: 13874

Answers (5)

Tharok
Tharok

Reputation: 1041

In Editor - Code Style - Java/JSON/etc - Tabs and Indents are two checkboxes:

  1. Use tab character - when not checked, Idea replaces tabs by spaces while typing
  2. Keep indents on empty line - when not checked, Idea removes tabs and spaces from lines where is no other content

Upvotes: 0

elmot
elmot

Reputation: 71

Besides noted IDE settings, please check if .editorconfig file exists in your project. The file may silently override IDE settings.

Upvotes: 0

bzak
bzak

Reputation: 495

There is an option 'keep indents on empty line'

enter image description here

Upvotes: 4

kugo2006
kugo2006

Reputation: 129

To restate the problem, you want the editor to not affect the whitespace indentations. Spaces should remain spaces and tabs should remain tabs.

I'm having a similar problem. It looks like IntelliJ has this feature:

Settings > Editor > Code Style, Indents Detection section, Detect and use existing file indents for editing option

Unfortunately, I don't think I can get it to work as expected for myself (version 2016.3.6), but it seems to be working for others.

Here's the original jetbrains blog post about it.

Upvotes: 5

acanby
acanby

Reputation: 2993

Assuming Java: Settings > Code Style > Java > Tabs and Indents > Use tab character. You can do the same for other languages too.

Upvotes: 1

Related Questions