IDEA makes annoying whitespaces changes


When I edit a file containing leading spaces rather than tabs, IDEA replaces the spaces with tabs whenever I do something like completing a word or generating an import statement.

I'm sure there's a way of preserving spaces/tabs (whatever the file contained originally), but I just can't find it!

Without this, minor changes look like major revisions when looking at the file's history. How can I preserve the original whitespace?


Does anybody know how to stop the auto formatting then? This really should be a simple configuration option somewhere, but I can't find it.

IDEA's basically reformatting all the whitespace in the file, so the revision history for the files I edit show a lot more changes than I actually made.

Surely someone knows how to turn this off? Any help appreciated, thanks.


Try to check: Settings->Global Code Style->General tab->Tabs and Indents->Use Tab Character (or check local code style, if you've overriden it on project level).



You should use a code style profile which has the same indentation settings as the files you are editing.



Thanks for the replies, but neither option is viable.

If I change my settings so I'm using tabs, the opposite happens - IntelliJ replaces all the spaces in the file with an appropriate number of tabs whenever I do any code generation (like adding an import statement).

Gordon, on any non-trivial project with a team of developers working on it, possibly using different IDEs, you can't possibly know how a file has been edited in the past and can't impose formatting rules.

There's no reason for IntelliJ to reformat the whitespace in the whole file. I can't believe nobody else is affected by this. Whenever I do an "svn diff", I can't see the wood for the trees. If you can't turn this 'feature' off, it must be a bug.


you can't possibly know how a file has been
edited in the past and can't impose formatting

I can't believe nobody
else is affected by this.

Perhaps because most development teams do indeed impose formatting rules via coding conventions?


I'd have to agree, code conventions are a must. I've only ever worked in one development team which didn't have coding conventions and their code was horrible.

I'd actually say (hope?) that you're development team is in the minority if it doesn't force coding conventions, Chris. The developers in our team use three IDEs quite happily and we don't have any issues working with each others' code.


I'm not saying we don't have code conventions. We all follow pretty much the same layout, although nothing is enforced. We don't have a strict rule that says 'thou shalt always use tabs'. I see that as a bit draconian, especially with a code base of a few thousand classes that has evolved over a few years, where some classes have not been touched for a long time. We never have problems where code is formatted one way by one programmer and another way by the next (apart from me making apparently massive changes because of the whitespace problem).

Most of our team use Eclipse, but I've stuck to my guns with IntelliJ. Are you telling me that I need to reformat the whole codebase to use tabs (or spaces), then make everyone set up their IDEs to adhere to that convention, just because of my problem with IntelliJ?

I'm only talking about whitespace here. I'm not talking about where you line up your braces or anything like that. If I open a Java file and add a couple of lines of code and use Ctrl-Space to complete a variable name, IntelliJ reformats all the white space in the file, so it looks like I've changed most of the file. C'mon, you can't tell me that's desirable behaviour!


BTW, I didn't mean this to turn into a rant. I'm sure there used to be some kind of setting in an older version to control this, but I can't find it now. Since nobody has pointed it out, I can only assume it's been removed.


I can see where you're coming from to be honest, although I'm pretty sure there has never been an option to keep the existing whitespace format (at least not since I've been using IDEA).

Maybe I'm far too draconian on my dev team, since whitespace is one of the things we're very strict upon :)

I take it you've tried doing SVN diffs with the option "Ignore Whitespace" set to "All"?


Thanks, I have tried that and it does work. However, it's not always possible to do that in other tools. For example, the command line "svn diff" doesn't appear to support ignoring whitespace changes. Nor does the Insurrection web front end to the repository that we're using.

I just can't bear the thought of trying to get the other 9 people on the team to adhere to a particular convention just because of a failing in IDEA. As a relative newcomer to the company, it was hard enough to use IDEA in the first place.

I love IDEA and I've used it for several years, but this is the first time I've noticed this problem. I've raised a bug anyway, so we'll see what happens.


I have people on my team who use Eclipse and I don't have any whitespace problems when dealing with their code.

Are you sure all the Eclipse people on your team haven't set Eclipse to use tabs rather than spaces?

Have you tried changing IntelliJ to use tabs instead of spaces on the General Tab of Global Code Style under settings?


Yes, I've tried using tabs. I thought that would solve it, but of course when I came to a file that was indented using spaces, they all got changed to tabs. I don't know whether the Eclipse users are using tabs or spaces. They're all probably using the default. But I do know that we seem to have a mixture of both whitespace characters in our codebase. Before Eclipse, they were all using Netbeans. Before that it was probably JEdit or emacs or vi.

My point is that it shouldn't matter what the files contain. IDEA shouldn't convert the lines one way or the other and there doesn't appear to be a way of stopping this.



I am also experiencing the same problem, in particular when I use Alt+Enter to add missing imports. It is not just an issue when different members of the team lay out code differently; it is not possible to set up IDEA (or any other IDE I have ever used) to always indent code exactly the way I want it, for example I format SQL like in the attachment.

It is also a point of principle - one of the reasons I use IDEA is because it doesn't get in my way and doesn't mess with my code unless I ask it to!

I too have a vague memory that this didn't use to happen in earlier versions of IDEA (I am using 5.1.2 build 4267 at the moment).


P.S. I have voted for your bug Chris :)


Apparently, I just opened up a thread asking the same thing. How could such a great IDE be lacking in this most basic feature? Don't change code unless I tell you too, period! The vast majority of projects I've been on have no set standards. And those few that have had spacing standards were surprisingly unproductive as are all projects that worry more about procedure, rather than actually accomplishing anything. This option would take all of ten minutes to add to the IDE and I know of at least one person on our team who stopped using Intellij because of this issue. There have got to be more out there.


+1 this auto whitespacing really sucks the big one.


when is it going to be fixed? 



Why hasn't this bug been fixed yet?

I don't want to hear any idealist "this is a feature" kinda talk.

Making code reviews harder is a bug, period, full stop.





Making code reviews harder is a bug, period, full stop.


I Wasted a whole half-day coz of this UNINTELLIGENT behavior.

I knew this would happen, so I carefully again googled and was advised 'Ignore WS' Option will make sure IJ ignores WS during commits. Hoping the latest version is upto snuff, it still happened: While the diff in VCS  DOES 'ignore' WS diffs, darn thing actually committed it all.

This is STUPID behavior led me to spend the rest of the day painstakingly having to revert then c&p multiple files code to work around this, which happens when we c&p from diff editors.

While I love IJ much more then Eclipse. I balk at the (very) few shortcomings that can easily be fixed and make our lives easier !

Why, why on earth would you not consider this a BUG ??


There is a "Paste Simple" option under the edit view that will paste as is without trying to special format it. 

This leaves you the option to format when you want it to, but otherwise leave it alone. 



That helps when pasting at least... which was always my main annoyance 


Well its not really the formatting but the tabs conundrum.

Tabs used to be a major player in the days of Notepad editors, but with these smart IDEs out there to format code for us, based on templates or whatever, its so ignominious to even honor these li'l bastids (tabs). I would agree that for code like Python this is important, but not for others which an IDE should be able to figure out.

First was the dire warnings that popup in IJ about tabs/spaces - who cares and we have to spend a good 10min figuring out how to shoo it away for good after 10 annoyances

When I stared & compared the code it looked exactly the same,

But my issue wasn't the paste, its the fact that it tells us one thing and does something else. It committed the code to GIT with WS diffs after promising NOT to do it !! Thats downright mean !

I wonder why no mod has butted in and asked us to post an issue in the bugs site, which I forgot.


I think it reproduces in so many different ways the mods are probably having a hard time understanding use-cases where the bug pops up.

If you post a screen-to-gif of your reproducer steps you could probably create a separate bug with that highlighted issue and get some attention. or someone might be able to help you with some sort of work around or way to not experience the whitespace mucking.

in my case i was super annoyed with this but realized by copy-pasting text into the editor with CTRL+V it will auto format the pasted contents. by simple pasting it relieved my issue and makes life great again. maybe there is a simple fix for your issue that will come to light. 


I had similar problems controlling my whitespace - and let’s be honest, you almost can’t program without being able to control your whitespace. I turned off some auto formatting stuff in IJ but it didn’t stop until I turned off an imported style module in my Scala builder, sbt - kinda like Maven or Ant or Gravy, uh Gradle. Anyways, it was like the heavens open up when I finally got it right.


Please report issues on YouTrack: So they could be checked and fixed.


Thanks Yaro, FYI for others, I posted a bug, let's hope it gets some traction !



I've similar problem and solved by adjust the setting on Strip trailing spaces on Save, I hope this help you to solve your problem also.


Thanks Rex See for your comment, it works for me !


I am also facing same problem where leading whitespace is replaced by tab and in "git diff" I can't see my modification instead whole file lines shown as modified. Also, there is no mechanism to control this behaviour in settings. How to solve this problem ? Even bug has been removed, getting 404 error. For time being I have stopped auto formating but this is overhead on me to format code manually. 


Open Menu: IntelliJ > Preferences > Editor > Code Style > Java > Spaces

Uncheck the box under "Before Parentheses" labeled "Method declaration parentheses"


Please sign in to leave a comment.