whole - format code android studio mac

Code formatting shortcut in Android studio (13)

Ctrl+Alt+L might conflict with Lock Screen shortcut in Ubuntu. In such case you can change the keyboard shortcut for Reformatting Code as follows:

File-> Settings-> IDE Settings-> Keymap

Search for Reformat Code and change the keyboard shortcut.

I have started developing with Android Studio. In eclipse I was using Ctrl+Shift+F but in Android studio it does not work, It will be different.

How can I jump to any method in .java. I was using Ctrl+O in eclipse.

Is it available? Can any one tell me that shortcut for code formatting?

Best key where you can find all commands in Eclipse is CTRL+SHIFT+L

by pressing this you can get all the commands in Eclipse.

One important is CTRL+Shift+O to import and un import useless imports.

Check this. Also you can change it as per your preference.

For Auto Formatting your Java/xml files in Android Studio use following commands:

As you are looking for a single point to go with your work as eclipse did, there is no such built in functionality in Android studio but it gives you the ability to do it through Macro, Follow these steps:

In studio open any of your source code file.

Press Ctrl + Alt + O This is used to find/optimize unused import.

If a dialog open select 'Dont show it again' and hit Run.

Go to Edit > Macros > Start Macro Recording.

Press Ctrl + Alt + O.

Press Ctrl + Alt + L. This formats your code. (Shift+ctrl+Alt+L for ubuntu).

Press Ctrl + S ,This saves your file;)

Go to Edit > Macros > Stop Macro Recording.

Save this created macro with name for instance:“Auto Formatting".

Boom, You have now successfully created your Macro, Now just add/assign a shortcut to it:

Open Preferences.

Search in the left bar for Keymap.

In the right hand pane, click in the search bar and type the name of your saved macro("Auto Formatting".)

Double click on your item. There might be two, it doesn’t matter which one you click on.

Click Add Keyboard Shortcut.

Set your keyboard shortcut to Ctrl + S.

Finally,Confirm overriding Ctrl + S to be your new macro.

For those who are wondering about the alignment issue inside bracket. JetBrains has this as in their issue tracking.

here is the answer:


I think is clear that for code formatting in Android Studio the combination keys are:

CTRL + ALT + L (Win/ Linux)

OPTION + CMD + L (Mac)

However, we forgot to answer about the Jumping into the method. Well to go into any declaration/implementation there three ways:

  1. Goto Declaration

CTRL + B or CTRL + CLICK (Win/ Linux)

CMD + B or CMD + CLICK (Mac)

  1. Goto Implementation

These commands show a list of all the classes/interfaces that are implementing the selected class/interface. On variables, it has the same effect as Goto Declaration.

CTRL + ALT + B (Win/ Linux)

CMD + ALT + B (Mac)

  1. Goto Type Declaration

These shortcuts will go into the declaration of the “AnyClass” class.

CTRL + SHIFT + B (Win/ Linux)

CTRL + SHIFT + B (Mac)

Additionally, there is a shortcut for Goto the Super Class. This will open the parent of the current symbol. Pretty much the opposite of Goto Implementation. For overridden methods, it will open its parent implementation.

CTRL + U (Win/ Linux)

CMD + U (Mac)

Just select the code and

  • on Windows do Ctrl + Alt + L

  • on Linux do Ctrl + Windows Key + Alt + L

  • on Mac do CMD + Alt + L

This solution from junaidp

Just to add to @user2340612 answer to switch keymaps to eclipse, the path for Android Studio 1.0.1 is:

File -> Settings -> Keymap (Under Editor option) -> Keymaps = Eclipse

The shortcut that worked for me is


You can optimize imports to remove the ones you don't use, and auto import the new classes.

Try this.

  • On Windows do Ctrl + Alt + L
  • On Linux do Ctrl + Shift + Alt + L for dialog to open and then reformat.
  • On Mac do CMD + Alt + L

Note: Here many answers for Linux is just Ctrl + Alt + L which is wrong. In Linux, doing Ctrl + Alt + L locks the system.

You can also use Eclipse's keyboard shortcuts: just go on preferences->keymap and choose eclipse from the dropdown menu.


The actual path is: File->Settings->(under IDE settings)->Keymap (thanks to @Dhinakaran Thennarasu)

You can use the following shortcut for code formatting: Ctrl+Alt+L

for code formatting in Android Studio
CTRL + ALT + L (Win/ Linux)
OPTION + CMD + L (Mac)

user can also use Eclipse's keyboard shortcuts: just go on Setting>>preferences->keymap and choose eclipse(or any one you like) from the dropdown menu.