79

How can I change spacing in Android Studio to use tabs instead of spaces? I tried Preference -> Editor but I don't see the option there. I'm using Android Studio for Mac

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

2 Answers2

110

Type in 'spac' in the search panel of the settings view.

You will find Editor -> Code Style->Java->Tabs and Indents->Use tab character.

Jakub Czaplicki
  • 1,787
  • 2
  • 28
  • 50
nhaarman
  • 98,571
  • 55
  • 246
  • 278
  • 1
    is there any way to replace the spaces I have written so far with tabs or should I do it manually? – Christopher Francisco May 13 '14 at 13:42
  • Use the auto format. It will change other stuff too unfortunately. – nhaarman May 13 '14 at 13:43
  • 14
    For those wondering, auto-format is: CTRL + ALT + L (Win/ Linux), and OPTION + CMD + L (Mac) – Jon Oct 12 '14 at 02:54
  • 25
    There is a way other than auto-format. Under Edit->Convert Indents. – terencey Nov 09 '14 at 09:23
  • 4
    There is also the setting `Editor`->`Code Style`:`Detect and use existing file indents for editing` - this was throwing me off because the file already had spaces and so future indenting also had spaces. – Wayne Uroda Jun 30 '15 at 02:06
  • @Terence thats great! But it doesn't catch `int a; __here_are_spaces__ // this is an int` – Chameleon Mar 27 '16 at 15:50
  • I was trying to set this for Kotlin files, but Kotlin didn't appear as a file type under Editor > Code Style until I searched for "kotlin" instead of "space." Now Kotlin appears whenever I open the preferences. – arlomedia Mar 14 '19 at 22:23
5

This is a little weird, but others may have the same issue I did.

Yes, follow the above directions, and do the normal changes in the config file. And guess what? it looks like it's still making spaces instead of tabs, even though the settings say TABS, not spaces!

Turn on "show whitespaces" (Editor -> General -> Appearance). And then turn it off. Looks like this is enough to reset the editor so that it is now following the rules you set in the preferences.

SMBiggs
  • 11,034
  • 6
  • 68
  • 83
  • 1
    Exactly the problem I was having and this worked. That bug should definitely be fixed. – Adam Aug 05 '16 at 03:27
  • yeah, it works now after these weird steps. Thanks for sharing. – mat Nov 09 '19 at 06:16
  • @LuckyLukeSkywalker I'm guessing that there are some strange state variables in Android Studio that are conflicting. I can only suggest playing around (clearing caches, removing or modifying config files, etc.) until you find something that works. Good luck! – SMBiggs Apr 26 '21 at 18:00