Develop Faster — Useful Shortcuts for Android Studio
Couple years ago, one of my seniors told me that “You can grasp skills of someone by paying attention to their usage of shortcuts”. While you can’t understand if someone can or can’t write some good code with this knowledge, you know over years you found yourself using more and more shortcuts for sake of speed.
So then, let’s begin shall we ? You may know couple of these, but here are some shortcuts I use and example usages.
Really ? New ?
Yeah. It’ll make creating new modules / packages / classes faster for you. It’s keymap name is “Other | New Folder | New”. I use “CMD + N”.
You can easily see some generation suggestions over a class, field, variable. It’s sometimes easier to find what you’re looking for in a class to override. I guess keymap name is obvious. I use “CMD + N”. It’s not the same thing as New above, new works on files, not around class. You can assign same shortcut for both.
And of course, for variables:
You don’t need to cut / paste and edit your code when you want something to be field and not a variable anymore, or you want to make it a parameter, or even method ! Extract it. You can specify different keys for each extract options, but I use one shortcut for “Main menu | Refactor | Extract” and type in extract type so I don’t need to remember shortcut for each type. I use “CMD + Shift + A”.
Rename quickly while changing that name everywhere it’s used by using “Main menu | Refactor | Rename…”. I use “CMD + Shift + Enter” for it.
I love this one. Start using it instead of copy pasting / moving your code. Keymap name is “Main menu | Code | Surround With”. I use “CMD + R”.
This will help you stop removing brackets. Really, it’s great. Saves me couple clicks everythime. Keymap name is “Main menu | Code | Unwrap / Remove”. I use “CMD + Shift + Backspace”.
I use this to navigate faster in a class. While there’s a Structure window on the left, right under your Project window, this one pops up a Structure dialog. Keymap name is “Main menu | Navigate | File Structure”. There are couple hints to have some idea about what’s in that class quickly. I use “CMD + O”.
Round icons tell you what it is: a class, a method, a field, an enum, an interface… Note that this icon changes. Sides will be trimmed if member is abstract. It’ll have a diamond badge for showing member is static. If member is final, it’ll have a pin badge on it.
Red lock near round icon means it’s private, key is protected, a little grey circle is package private and green opened lock is public.
Here’s a fast usage.
If you wrap your code with regions, you can increase readability of your structure dialog !
Beware, leave a line after you write regions tho. If you don’t, it seems to add region name to randomly among members.
I use navigate to file instead of Search Everywhere for better results. Search all will give you results collected from everywhere, while Navigate will work with files in your modules. Keymap is “Main menu | Navigate | File…”. I use “CMD + T”.
This opens up a window where you can find recent files you opened. It’s easier to switch between files with this instead of scrolling to tab and clicking on it. Keymap name is “Main menu | View | Recent Files”. I use “CMD + E”.
You can also open up Android Studio panes from here like Project, Structure, Logcat, Build Variants, Event Log…
Find in Path
And this is what I use for searching a file everywhere. You can change the search module or create custom scopes for your searches. It’ll also show a preview for where it found what you searched. Keymap is “Main menu | Edit | Find | Find in Path…”. I use “CMD + Shift + J”.
This is great to see what’s wrong & apply suggested fixes fast. Keymap name is “Other | Show Intention Actions”. I use “CMD + 1”.
Still putting curly brackets or your semicolon yourself ? There are couple keymap names for this:
- Editor Actions | Choose Lookup Item and Invoke Complete Statement
- Editor Actions | Complete Current Statement
- Main menu | Edit | Complete Current Statement
If you make all three the same key, it’ll work like a charm. I use “CMD + Enter”.
Well, that’ll be all for now. I hope these will help you get faster ! After I learned couple of these shortcuts, I almost don’t waste time I clicking around. Still, of course, you can still use “Main menu | Edit | Copy” and “Main menu | Edit | Paste”.
P.S. : You can use keyprompter plugin, it’ll warn you about the shortcuts you could use instead of clicking around.