Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure Android studio to add new line at end of file?

I use Android Studio and when I commit to a repo on GitHub and view git diff I see a red marker at end of line for few files with a warning 'No newline at end of file'. How can I configure Android Studio to ensure that it does add a newline at file of file for every file. Thank you.

like image 842
sujithvm Avatar asked Jun 07 '14 04:06

sujithvm


People also ask

How do I add a line break in Android?

Add Line Breaks to a TextView Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.

How do I add a new line to a string in XML?

Add \t for tab and \n for new line.

How do I create a new line in Kotlin?

\n - Inserts newline.

Why does Android studio have lines?

That line historically represents the margin of A4 paper, which is useful only if you need to print the code. Old school says that you should keep your code inside that margin, to guarantee much portability.


1 Answers

Yes, you can configure Android Studio to automatically add a new line at the end of a file.

File | Settings... menu, then Editor under IDE Settings, then check the Ensure line feed at file end on Save option box.

This will only take effect on freshly edited files after the setting has been enabled.


UPDATE

On newer versions of Android Studio, the preference location has changed to

File > Preferences > Editor > General > Ensure line feed at file end on Save

like image 52
Mark Bowker Avatar answered Sep 18 '22 10:09

Mark Bowker