Top (unknown) keyboard shortcuts in Android Studio — Part II

Hi! It’s time for the next part about my top keyboard shortcuts that I use in Android Studio on my daily basis. If you didn’t read the previous part, you can do it here:

Today I’ll focus on shortcuts for refactoring and editing code. Let’s start!

#1 Extracting method/parameter

During the refactoring, one of the most commonly thing to do is to extract something. With this shortcuts you can do it quickly with the whole methods…

macOS: Cmd + Alt+ M
Windows: Ctrl + Alt + M

… or single parameters:

macOS: Cmd + Alt+ P
Windows: Ctrl + Alt + P

Or more generally with Cmd+Alt also variables (V), fields (F), constants (C), etc. Now go and extract some kitties! 🐱

#2 Surround with

You can also surround some code with the popular statements — if/else, try/catch, comments block. Look at the example:

macOS: Cmd + Alt+ T
Windows: Ctrl + Alt + T

#3 Smart line split & join

If you need to split the line, but you want cursor to stay in the same position, you can use smart line split:

macOS: Cmd + Enter
Windows: Ctrl + Enter

Or if you want to join lines in the similar way, you may use smart line join:

macOS: Shift + Ctrl + J
Windows: Shift + Ctrl + J

#4 Moving statements

If you need to change e.g. order of methods, here’s one very handy shortcut to do it:

macOS: Shift + Cmd + ↓/↑
Windows: Shift + Ctrl + ↓/↑

You can use it also to change order of lines, fields, method invocations, classes and many more!

That’s all! I’m curious of yours top unknown shortcuts that you use to edit the code. Let me know in comments!

If you liked this post, don’t forget to 👏!

Flutter GDE / Android & Flutter Developer / blogger / speaker / cat owner / travel enthusiast

The (retired) Pub(lication) for Android & Tech, focused on Development