He that will do his work well must first sharpen his tools. IDEA tool compared to eclipse is more convenient to use, the article detailed introduction of common shortcuts and other small skills, I hope you like.

Search globally for classes and include Jar package content

When you want to search globally for class files in Jar packages, do the following:

1. Hit CTRL + Shift + F

2. Double-click Shift to bring up the global search box and check include non-project classes.

replace

ctrl+shift+R

Copy the code

One click formatting code

Ctrl+Alt+L

Copy the code

Writing code is like writing calligraphy. Spacing between codes is better.

View recently edited files

Ctrl+E

Copy the code

Check out the most recently edited places

Ctrl+Shift+E

Copy the code

Close the current file

Shift+Click

Copy the code

Generate the constructor /Getter/Setter

Alt+Insert

Copy the code

annotation

Ctrl+/

Ctrl+Shift+/

Copy the code

Increase if/try… Catch method etc.

CTRL+ALT+T

// Place the selected code inif/while/for/tryIn the

Copy the code

Returns to last viewed location

Ctrl+Alt+left/right

Copy the code

It can be found that the shortcut key can be used to return to the last browsing position only when dragging with the mouse wheel. If dragging with the left mouse button, the shortcut key is invalid.

Returns the location of the last edit

Ctrl+Shift+Backspace

Copy the code

See where the method is called

Alt+F7

Copy the code

Select the search range for the first time

There’s also a similar shortcut

ctrl+alt+h

Copy the code

The difference between the two:

  • alt+f7The results are in a hierarchy from large to small, resulting in a tree of modules -> packages -> classes -> methods
  • ctrl+alt+hThe structure of the search results is target method -> method A that calls target method -> method B that calls A…

Go to the superclass definition

Ctrl+U

Copy the code

The current method expands and collapses

Ctrl+"+ / -"

Copy the code

refactoring

rename

Shift+F6 

Copy the code

All files, class names, function names, and attribute names can be renamed using Shift+F6. (Except for configuration files such as XML)

Refactoring function

Ctrl+F6

Copy the code

Used to modify the argument list of a function, or the return value.

extracting

Extract the duplicate content as follows:

@Test

public void keyTest(a){

    List<String> list = new ArrayList<String>();

    list.add("hresh");

    list.add("hresh");

    list.add("hresh");

    list.add("hresh");

    list.add("hresh");

    list.add("hresh");

}

Copy the code

Adding the same thing to the add() method of the code above is best defined as a variable.

Use the shortcut keys Ctrl+Alt+ V

Extract static variables

Ctrl+Alt+C

Copy the code

Hot keys used

psvm
public static void main(String[] args) {}

Copy the code
sout
System.out.println(a);

Copy the code
“ABC”. Sout
System.out.println("adc");

Copy the code
psf
public static final

Copy the code
ifn
///Builds to determine whether it is not null

if(x ! =null) {



}

Copy the code
fori
/// generate a simple for loop

for (int i = 0; i < ; i++) {

}

Copy the code
itli
// Generate a for loop for list

for (int i = 0; i < list.size(); i++) {

    String s = list.get(i);

}

Copy the code
itar
/// Generate a for loop for the array

int[] array = {1.2.3.4.5};

for (int i = 0; i < array.length; i++) {

    int i1 = array[i];

}

Copy the code
iter
/// Generate an enhanced for loop based on the most recent array/collection

for (String s : list) {

}

Copy the code
list.for
/// generate the specified array to enhance the for loop

for (String s : list) {

}

Copy the code
iten
// generate an enumeration traversal

while (enumeration.hasMoreElements()) {

    Object nextElement = enumeration.nextElement();

}

Copy the code
itit
///Generates an iterator

while (iterator.hasNext()) {

    Object next = iterator.next(a);

}

Copy the code
itco
///Generate a Collection iterator

for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {

    String next = iterator.next(a);

}

Copy the code
“XXX”. Try
/ / / generates a try... catch

try {

    "xxx"

catch (Exception e) {

    e.printStackTrace();

}

Copy the code

Alt+Enter

Alt + Enter is the most special shortcut key, including the functions of importing packages, automatically correcting code to solve problems, and generating return values. It is the most frequently used shortcut key in code writing

If your IDEA does not use this shortcut, use the following solution:

1, go to Settings->Keymap-> Search: Show Intention Actions shortcut. Make sure the default shortcut keys are correct.

2, Editor->intention-> Search: refactorings, make sure the following items are checked.

other

The following contents are configured according to personal habits:

Ctrl+Y: Delete the current line, there is a similar shortcut Ctrl+X, but the latter cannot delete more than one line at a time, I prefer Ctrl+D to delete.

Ctrl+D: Copy lines. I prefer Ctrl+Alt+Down.

Alt+ comma: Move to current code header.

Alt+ period: move to the end of the current code.

In addition to the above, if you are also interested, check out the Idea Usage Tips Record.

The follow-up will always record the new use of IDEA tips, I hope everyone can use IDEA efficiently for development work.