whole Code formatting shortcut in Android studio

format code android studio mac (16)

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.

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?

Really, I went to this thread because of my Ubuntu locks screen after this shortcut Ctrl + Alt + L. So if you are have the same problem just go to the Settings - Keyboard - Shortcuts - System and change the default shortcut for the "Lock screen".

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

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)

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.

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

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.

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)


Ctrl + Alt + L


Ctrl + Shift + Alt + L


Option + Command + L

Reference : Key Commands and here is full commands for Windows/ Linux users and for Mac users

Update for Ubuntu As Rohit faced the problem in Ubuntu to format code shortcut, because the Ctrl + Alt + L key is used to lock the screen in Ubuntu.

I found that Ubuntu which handles the key event first. So try to change the Ctrl + Alt + L action in Ubuntu just to be sure.

Steps are :-

Go to System Tools -> System Settings -> Keyboard -> Shortcuts Tab -> System -> Lock Screen

Select the row New Accelerator... will be visible then press any Special key with Alpha key (like Shift + L). You changed the key shortcuts.

Now check format key in Studio.


Ctrl + Alt + Shift + L (for a dialog)

Update came from Henry Chuang, and also in another answer given by user2340612.

You can also use Eclipse shortcuts. Windows and Linux, go to File > Settings > Keymap , Mac OS X, go to > Preferences > Keymap and choose Eclipse from the dropdown menu.

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.

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

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.

For formatting code on Android Studio on Linux you could instead use CTRL+ALT+SUPER+L. You could use this and avoid having to change the system shortcut. (SUPER key is the windows icon key besides the ALT key).