When I selected my codes to indent it using CTRL+ALT+L, my Android Studio seems to always add a new line after each comma. How do I avoid this?
Here's what currently is happening
and here's how I need it to be
I have tried almost every things under Settings > Editor > Code Style > Kotlin, but I still couldn't get Android Studio not to add these new lines after comma
This is driving me nuts. I just want to write a series of // single line comments aligned on the same column but when I hit the enter key Android studio auto-indents and I get the following:
//Todo do need to determine next fragment to navigate to
//
Instead of:
//Todo do need to determine next fragment to navigate to
//
It also injects a tab instead of spaces so that the backspace key brings me back to the end of the previous line.
I can't find anything in settings.
Thanks
Seems the options are in:
File -> Settings -> CodeStyle -> C/C++ ->
Uncheck these options:
[ ] Use Tab Character
[ ] Keep Indents on Empty Lines
Then [Apply] then [OK]
In my case, I even have to Exit/Re-enter Android Studio, in order for the changes to take effect (I believe it's a bug).
And also, placing Settings, under File menu, is NOT quite trivial for me (at least in my other IDE apps).
When I'm working in Android Studio and I want to make, for example, a new button. I type button and Android Studio gives me the correct line for inserting a button. When I press enter, Android Studio inserts it but it puts it in one line (see image)
But I want the code to be sort by attribute (see image)
The last one, I see in every tutorial, but mine doesn't do it automatically.
Does anyone know how to fix this? Now it takes so much time to align the code.
You can reformat your code with the below keyboard short cut.
Ctrl + Alt+ L
This short cut will format you complete file code. Whether that is XML or Java Code.
Hope this helps you.
Alternatively
You can do the same by going to your IDE Main Menu and selecting Code > Reformat Code or if you're only fixing alignment of text then Code > Auto Indent Lines.
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.
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:
Export the settings scheme.
Open saved xml file.
Find <codeStyleSettings language="kotlin"> tag (or create)
Add the WRAP_LONG_LINES setting manually:
<codeStyleSettings language="kotlin">
...
<option name="WRAP_LONG_LINES" value="true" />
</codeStyleSettings>
Save edits and and import back the scheme.
Here you go!
MacOS:
Click on Android Studio ( left top corner )
Click Preferences
Type Code Style in search
Click on Code Style
There is a filed right to the 'Hard wrap at' - you can enter needed about of symbols you need
In File | Settings, select "Editor", then "Code Style". There is an option "Wrap when typing reaches right margin".
Edit: Just tried it, and it doesn't seem to work. Anyway, maybe the option "Use soft wrap" in the "General" group is more what you want.
#Solace, actually #Fahim Faysal's answer is quite close to what you need, but since you want to solve the problem no matter how long a statement I type on a single line, it never automatically goes to the next line, 2 more steps you need to follow:
[Step 9] type the max length you prefer at `"Hard wrap at" ()
[Step 10] change "Wrap on typing" from Default: No or No to Yes
With version 4.1.2 and with Dart language you need to go to "File/Settings/Editor/Code Style/Dart" and modify the "Line length" to the preferred number.
In Android Studio:
File->Setting->
Editor->code Style->java->Wrapping and braces(tab:right side)->keep when reformatting->Line break(make unchecked)
You can change the max column width from:
File > Settings > Editor > Code Style > Right Margin (columns)
Android Studio 3.5:
Mac -
Android Studio > Preferences > Editor > CodeStyle > HardWrap at: ____
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.
Just open the settings, search for kotlin and look for kotlin under code style.
On the top right hand side of the settings window you'll see Set from..., click on it.
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
My Environment:
Ubuntu 18.04
AndroidStudio 3.3.2
My operate:
File -> Settings -> Editor -> Code Style
Scheme -> select Project
Hard wrap at '120'
Apply
To move the grey vertical line, that tells Android Studio where to wrap your code, go to
Settings- Editor- Code Style- Java or Kotlin- Wrapping and Braces- Hard wrap at
and enter the number of characters, where the line should be.
For dart
settings => code style => Dart => Line length
In settings/code style/kotlin/wrapping and braces replace the "do not wrap" values with "wrap if long"
You can change the Hard wrap at param
What does the following arrow icon mean in the Visual Studio 2012 gutter window? I've never seen it before.
This particular line of code has nothing special about it, nor do I recall doing anything to this line that would cause an arrow to appear. It's definately attached to this line of code. Moving the line of code down causes the arrow to follow.
I have no add-ons installed in Visual Studio.
It marks a Task List shortcut. You add them with Edit > Bookmarks > Add Task List Shortcut, [Ctrl+E,T] keystroke. That adds an entry to the task list, use View > Task List to display it. Select "Shortcuts" in the combobox. You'll see a list of all the shortcuts you added. Double-click an entry to jump to the line.
Remove it again with Edit > Bookmarks > Remove Task List Shortcut, [Ctrl+E,T] again.
NOTE: In visual studio 2015 and above, its [Ctrl+K,Ctrl+H]