How Do You Stop Android Studio From Deleting Trailing Spaces?

3.4k views Asked by At

My Android Studio will continuously and automatically delete trailing white spaces. Particularly if it's a blank line with nothing but white spaces. I can even add the spaces back in manually and it'll get rid of them again right in front of me within minutes.

This is causing an issue for me because I am working on a large project that has been around for a while and our diff system shows changes all over the place as a result (our diff system doesn't have an option to turn it off and we can't switch systems). This makes code review more difficult and is causing headaches as a result.

How can I prevent Android Studio from doing this? I can't find it in the settings.

Thanks

3

There are 3 answers

0
free3dom On BEST ANSWER

You can disable it as follows:

  1. Go to Settings (File -> Settings)
  2. Find the Editor tab (under IDE Settings)
  3. Select NONE from the dropdown list next to Strip trailing spaces on Save. You can also set it to Modified Lines since that would also fix the problem for your specific needs.

The reason it happens automatically is because it saves changes automatically when idle. You can change this behavious as follows:

  1. Go to settings
  2. Find the General tab (also under IDE Settings)
  3. Check or uncheck the desired boxes under Synchronization
0
bobobobo On

Nowadays, there are 2 places you need to worry about:

  1. Settings / Editor / General / Remove trailing spaces on: OFF remove trailing spaces

  2. Settings / Editor / Code Style / Enable EditorConfig support OFF enable editorconfig support

0
Andrew On

In Android Studio 2.0 you can find this setting in Preferences -> Editor -> General -> Other -> Strip trailing spaces on Save.

enter image description here