Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I auto-remove trailing whitespace in Android Studio?

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?
like image 940
qix Avatar asked Oct 14 '14 06:10

qix


People also ask

How do you get rid of trailing white space?

Type M-x delete-trailing-whitespace to delete all trailing whitespace. This command deletes all extra spaces at the end of each line in the buffer, and all empty lines at the end of the buffer; to ignore the latter, change the variable delete-trailing-lines to nil .

How do you get rid of leading and trailing white spaces?

To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

What function is used to remove leading and trailing spaces?

The Trim function The most obvious (and generally efficient) method for removing both leading and trailing space is to use the TRIM() function.


2 Answers

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)

like image 160
jwir3 Avatar answered Oct 22 '22 16:10

jwir3


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

like image 9
qix Avatar answered Oct 22 '22 16:10

qix