Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set max line length in Android Studio code editor?

How can I set a maximum length for Android Studio's code editor, or may be set a word wrap?

In my Android Studio, no matter how long a statement I type on a single line, it never automatically goes to the next line, but rather a horizontal scroll bar appears.

When I autoformat using the Ctrl+Alt+L (reference), nothing happens.

My SO or Google search found a lot of material on this for Eclipse, but not for Android Studio.

like image 322
Solace Avatar asked Jun 15 '15 17:06

Solace


People also ask

How do you limit a line length in VSCode?

In VSCode, go 'Code -> Preferences -> Settings' and search for "python formatting black args". A few notes about line lengths in Python: PEP8 recommends a line length of 79 characters (72 for docstrings) Black sets line lengths to 88 characters by default.

What is the vertical line in Android Studio?

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

If you need not a soft wrap,
but actually, brake one long line onto several lines you need:

Go to Preferences(mac) or Settings(windows) -> Editor -> Code style -> Java/Kotlin -> Wrapping and braces (tab) -> Check "Ensure that right margin is not exceeded"

Now try to reformat your code:
press OPTION (ALT) + CMD + L on your Mac (or CTRL + ALT + L on PC)

Edit 13.02.19

As noted in comments this option seems not available in settings for Kotlin. However, there is a workaround to manually add it.
Here is what it takes to make it work:

  1. Export the settings scheme. enter image description here

  2. Open saved xml file.

  3. Find <codeStyleSettings language="kotlin"> tag (or create)

  4. Add the WRAP_LONG_LINES setting manually:

    <codeStyleSettings language="kotlin">    ...    <option name="WRAP_LONG_LINES" value="true" /> </codeStyleSettings> 
  5. Save edits and and import back the scheme.

  6. Here you go!

like image 134
Leonid Ustenko Avatar answered Sep 27 '22 17:09

Leonid Ustenko