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

前端 未结 12 1098
温柔的废话
温柔的废话 2020-12-29 01:31

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

相关标签:
12条回答
  • 2020-12-29 01:56

    The existing answers already answer the question in straight forward way. As a different approach you could set the style guide to kotlin style guide code style. Then if you do alt + ctrl + l as you did, you'll see auto wrap as you expected.

    1. Just open the settings, search for kotlin and look for kotlin under code style.

    2. On the top right hand side of the settings window you'll see Set from..., click on it.

    3. Then on predifined style > kotlin style guide

    If you'd like to follow the kotlin formatting style this could reduce more effort. For more information: https://developer.android.com/kotlin/style-guide

    0 讨论(0)
  • 2020-12-29 01:56

    In settings/code style/kotlin/wrapping and braces replace the "do not wrap" values with "wrap if long"

    0 讨论(0)
  • 2020-12-29 01:58

    In Android Studio: File->Setting-> Editor->code Style->java->Wrapping and braces(tab:right side)->keep when reformatting->Line break(make unchecked)

    0 讨论(0)
  • 2020-12-29 01:59

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

    Go to Preferences -> 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.

    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!
    0 讨论(0)
  • 2020-12-29 02:00

    My Environment:

    • Ubuntu 18.04
    • AndroidStudio 3.3.2

    My operate:

    • File -> Settings -> Editor -> Code Style
      1. Scheme -> select Project
      2. Hard wrap at '120'
      3. Apply
    0 讨论(0)
  • 2020-12-29 02:01

    Android Studio 3.5:

    Mac - Android Studio > Preferences > Editor > CodeStyle > HardWrap at: ____

    0 讨论(0)
提交回复
热议问题