44

Similar to the question for eclipse,

  • How can I auto-remove trailing whitespace from the entire file being edited?
  • How can I auto-remove trailing whitespace only from the lines I changed?
Community
  • 1
  • 1
qix
  • 7,228
  • 1
  • 55
  • 65

4 Answers4

59

You can also enable it on save via the following preference (Editor -> General -> Other):

enter image description here

And for those wondering,

"Always keep trailing spaces on caret line"

If this option is selected, trailing spaces will not be stripped on the line where the caret is placed on save operation (for example, when you switch to another window).

(bigger image)

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
jwir3
  • 6,019
  • 5
  • 47
  • 92
  • 1
    And for those wondering, **"Always keep trailing spaces on caret line"** means _"If this option is selected, trailing spaces will not be stripped on the line where the caret is placed on save operation (for example, when you switch to another window)."_ – Joshua Pinter Dec 14 '18 at 21:36
  • As of 2023, the option is located in Preferences > Editor > General page, in the On Save section near the bottom. – simpleuser May 08 '23 at 03:55
9

Ha, it's as simple as Code->Reformat code... (option-cmd-L)

qix
  • 7,228
  • 1
  • 55
  • 65
  • If your project uses native debugging and includes cxx files, this will have unintended side effects, use with care. – papezjustin Jul 31 '18 at 02:45
1

In Window You can use Ctrl + alt + enter reformat code in your Android studio it is best way indent code properly manner

Bhavnish
  • 42
  • 1
  • 6
0

A simple shortcut to do this easy is just Ctrl + alt + L .

Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42