Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

This article also participated in the “Digitalstar Project” to win a creative gift package and creative incentive money

A good idea can improve our work efficiency. If we master some shortcut keys, it can help us liberate from tedious and repetitive work, and the efficiency of code writing will be higher. I recently read some tips to share with you

Software environment

  • Mac/Win/Linux: Built-in default shortcut keys
  • AndroidStudio v4.1.1
  • The following shortcut keys should be adjusted according to your keyboard for different external keyboards

Parameters of the tip

What if a method argument is super long and you don’t know what the argument is? We can use the following shortcut keys

  • Mac: Cmd + P
  • Win/Linux: Ctrl + P

Automatic extraction method

When we optimize code, we will see smelly and long code, and our traditional way is to create a new function and copy the code, this process can be done by using the following shortcut keys

  • Mac: Cmd + Alt + M
  • Win/Linux: Ctrl + Alt + M

Automatic extraction parameter

During the development process, we found that it is better to pass in the variables used by the function as parameters. If you manually modify the function, it will be tedious to modify the function in every place. The following shortcut keys can free you

  • Mac: Cmd + Alt + P
  • Win/Linux: Ctrl + Alt + P

Of course, if you just want to reload the method, check the box that pops up

Automatic variable generation

  • Mac: Cmd + Alt + V
  • Win/Linux: Ctrl + Alt + V

Searches for whether a method is called

We are refactoring, optimizing, or reading someone else’s code. To find out who called a method, use the following command

  • Mac/Win/Linux: Alt + F7

Refactoring shortcuts

When we refactor, we can do a lot of things with shortcut keys, but there are so many shortcut keys that we can’t remember all of them. There is one shortcut that will help us

  • Mac: Ctrl + T
  • Win/Linux: Ctrl + Alt + Shift + T

The parcel code

  • Mac: Cmd + Alt + T
  • Win/Linux: Ctrl + Alt + T

Batch rename

If during development or optimization, you find that the variable name is not good, or the word is misspelled, and you need to change all the variables used, the following shortcut can free your hands

  • Mac/Win/Linux: : shift + F6

Look at the method call hierarchy

Sometimes when we are reading code and want to know what the call structure of a method looks like, one of the following shortcuts will help you

  • Mac: Control + Option + H
  • Win/Linux: Ctrl + Alt + H

Look at the hierarchy of classes

When reading the source code, you can use the following shortcut keys to find out what the call structure of a class looks like

  • Mac: Control + H
  • Win/Linux: Ctrl + H

Error prompt

When writing code, you may encounter the warning given by IDEA. The following shortcut keys can help you effectively solve the warning

  • Mac/Win/Linux: Alt + Enter

Displays all methods of the current class

When reading other people’s code, or when reading source code, we want to see what methods, constants, variables, and so on the current class has, the following shortcut will give you a big picture, very useful

  • Mac: Cmd + Fn + F12
  • Win/Linux: Ctrl + F12

The highlighted

When we need to see where a variable is called, this shortcut identifies all the places where the variable is used

  • Mac: Cmd + Shift + Fn + F7
  • Win/Linux: Ctrl + Shift + F7

Quick jump to the parent class

When you’re reading code and you want to jump to the parent class, the usual way to do this is to go back to the beginning of the class and click there. If the code is long, it’s inefficient

  • Mac: Cmd + U
  • Win/Linux: Ctrl + U

Quick jump to implementation

An interface has multiple implementations. When you click on a method of an interface and want to see its different implementations in the subclass, this shortcut helps you quickly jump to the implementation of the subclass

  • Mac: Cmd + Option + B
  • Win/Linux: Ctrl + Alt + B

Overwrite or implement methods

This shortcut is very simple, pop up a box for you to choose to override or overwrite a method

  • Mac: Control + O
  • Win/Linux: Ctrl + O

Generate default methods

If we want to quickly generate class default methods such as constructors, toString(), setters (), Gettter(), and so on, we can use the following shortcuts

  • Mac: Cmd + N
  • Win/Linux: Alt+Insert

Bulk changes

This is a very useful function, in the development process may encounter batch modify a certain string, this shortcut can make your efficiency N times

  • Mac: Ctrl + G
  • Win/Linux: Alt + J

Jump easily between layout files

There are two common ways to jump between Activity/Fragment/Adapter/Dialog and its associated layout files during development:

Methods a: Click the icon shown in the picture to jump to the corresponding layout file Method 2:Use the shortcut key to jump, the effect is as follows

  • Mac: Ctrl + Cmd + Up (Up arrow)
  • Win/Linux: Ctrl + Alt + Home

bookmarks

We often need to jump from one class to another while developing or reading code. We just need to put a bookmark in one place to jump back. This is a very useful feature.

Add/Remove bookmarks:

  • Mac: Fn + F3
  • Win/Linux: F11

Add/Remove bookmarks (while marking) :

  • Mac: Fn + Option + F3
  • Win/Linux: Ctrl + F11

View all bookmarks and jump back to where you started

  • Mac: Fn + Cmd + F3
  • Win/Linux: Shift + F11

instructions shortcuts
Parameters of the tip Mac: Cmd + P

Win/Linux: Ctrl + P
Automatic extraction method Mac: Cmd + Alt + M

Win/Linux: Ctrl + Alt + M
Automatic extraction parameter Mac: Cmd + Alt + P

Win/Linux: Ctrl + Alt + P
Automatic variable generation Mac: Cmd + Alt + V

Win/Linux:Ctrl + Alt + V
Searches for whether a method is called Mac/Win/Linux: Alt + F7
Refactoring shortcuts Mac: Ctrl + T

Win/Linux: Ctrl + Alt + Shift + T
The parcel code Mac: Cmd + Alt + T

Win/Linux: Ctrl + Alt + T
Batch rename Mac/Win/Linux: shift + F6
Look at the method call hierarchy Mac: Control + Option + H

Ctrl + Alt + H
Look at the hierarchy of classes Mac: Control + H

Win/Linux: Ctrl + H
Error prompt Mac/Win/Linux: Alt + Enter
Quick jump to the parent class Mac: Cmd + U

Win/Linux: Ctrl + U
Quick jump to implementation Mac: Cmd + Option + B

Win/Linux: Ctrl + Alt + B
Displays all methods of the current class Mac: Cmd + F12

Win/Linux: Ctrl + F12
Delete rows Mac:Cmd + Delete

Win/Linux:Ctrl + Y
Automatic completion Mac/Win/Linux: Enter/Tab
Overwrite or implement methods Mac: Control + O

Win/Linux: Ctrl + O
Generate default methods Mac: Cmd + N

Win/Linux: Alt+Insert
inline Mac: Cmd + Alt + N

Win/Linux: Ctrl + Alt + N
Bulk changes Mac: Ctrl + G

Windows/Linux: Alt + J
Jump easily between layout files Mac: Ctrl + Cmd + Up

Win/Linux:Ctrl + Alt + Home
Add/remove bookmarks Mac: Fn + F3

Win/Linux: F11
Add/Remove bookmarks (and mark them) Mac: Fn + Option + F3

Win/Linux: Ctrl + F11
View all bookmarks Mac: Fn + Cmd + F3

Win/Linux: Shift + F11