Three shortcuts on Android Studio
Introduction
Power users have always been using keyboard shortcuts to speed up their workflow, to keep their hands on the keys and prevent having to switch between them and the mouse.
Today, I want to share with you my three favourite shortcuts that I’m using on a daily basis. They speed up my workflow and improve the quality of the code I’m producing.
#1 Search Faster: Double-Shift
Easy to remember and to reach without contortions, tap twice on Shift, left and/or right. This shortcut empowers you to search for Files, Classes, Symbols and Actions.
I’m sure everyone knows what to expect when searching for files and for classes.
For this reason, I would like to take a moment to encourage you, to use this shortcut to search for Symbols and Actions.
Symbols can be a method name, a variable/constant name, or the ID of an element in a layout. That makes the access to such symbols very convenient.
Actions are basically direct access to all the menu items and settings, but also your Gradle tasks.
Even though you should definitely use Control-R to run a build, when it comes to building a specific flavour, Double-Shift makes it quick to access.
Bonus tip, you can assign your own shortcut to your favorite Action by pressing Option-Return while the item is highlighted…and who knows, that might become your new favourite shortcut!
#2 Code Pretty: Option-Command-L
Android Studio doesn’t require you to save your work anymore, everything is saved automatically. Let’s replace Command-S with Option-Command-L, a bit more complicated, I agree, but thanks to this shortcut, your code will be re-indented, unused imports will be cleaned up… in a few words: it just looks great. This works for Kotlin, XML, Java, JSON files…
If you work in a team, make sure your teammates share the same formatting/code style settings, so you don’t get conflicts because of formatting in your version manager. For that, head to Settings > Editor > Code Style
#3 Be a Better Coder: Option-Return
Android Studio has become very smart in assisting developers to follow the best way to code. Whenever a bit of code could be improved, Android Studio underlines the keyword so you can make it better.
Place the cursor on the underlined code section, hit Option-Return, and your code will be refactored with the best way to write it.
For example, this can help you to transform if-else statements into when in Kotlin without effort. I can tell from experience that this shortcut is like having a personal assistant when it comes to accelerated coding.
Conclusion
We have just scratched the surface with these three shortcuts that I love. There are many more to discover, such as Control-G, Command-Shift-F, Control-R, Control-Space…
If there are shortcuts that you love, please share your tips and tricks in the comment section!