Complete IDEA tutorial, GitHub address:

https://github.com/judasn/IntelliJ-IDEA-Tutorial

An overview of the


Before I wrote an article about IntellIJ IDEA [IntellIJ IDEA artifact actually has these tips], mainly to list some IntellIJ IDEA tips that we may not use or do not use very much, but are very useful. Due to space reasons, only a small part is listed, so the following article will continue to supplement some tips of IntellIJ IDEA.


Don’t easily customize shortcuts


There are a lot of operations. IntellIJ IDEA does not set the default shortcut keys for us, and users need to define the shortcut keys by themselves. Such as:

  • Rebuild Project

  • Compare With Branch

Many programmers customize shortcuts to enable mouseless programming in IntellIJ IDEA, but there are three areas you might want to pay attention to.

  • Shortcuts often conflict with those of other applications.

  • There are too many custom shortcuts that you can’t easily remember.

  • When using another colleague’s IDEA (for example, to help locate problems), your custom shortcut keys won’t work.

In fact, every operation in IntellIJ IDEA can be seen as an action. We can use CTRL + Shift + A to enter the action we want to use. For example, the Rebuild Project mentioned above. You can start by pressing CTRL + Shift + A, then type Rebuild Project and press Enter.

For myself, CTRL + Shift + A is my most frequently used shortcut, aside from the basic one.


Be careful with CTRL + Alt + H


CTRL + Alt +h is very useful, but there is a pitfall when the same method is called more than once, as in the following code:

public class TestService { public void test1() { System.out.println("aa"); } public void test2() { test1(); } public void test3() { test1(); // After countless business operations, movie test1() method test1() again; }}

Copy the code

If we want to know where test1() is called, CTRL + Alt + H won’t list it correctly. Because CTRL + Alt + H only tells you the level of the call.

CTRL + Alt + H will simply tell you, somewhere hidden, that test3() called test1 () twice. This is very easy to trap developers, because most people may not pay much attention to the number of calls, so when fixing the bug, they will think that all the changes have been made.

If you want to list exactly where test1 () is called, you need to use Alt +f7.

Especially when reading extremely complex business code, Alt + F7 is appropriate.

Of course Alt +f7 can also be applied to variables, listing where in a class that variable is used.


CTRL + Alt + H The two most frequently asked questions


I am often asked by my colleagues and netizens.

How to use CTRL + Alt + H to jump to source code, and how to return to the corresponding view of CTRL + Alt + H.

Go to source code

It’s pretty simple. After CTRL + Alt + H, use the down or up arrow, select a call, and press F4 to jump to source code.

How do I get back to CTRL + Alt + H view

This truth has been asked hundreds of times, it is actually very simple, when you use F4 to jump to the source code, directly use Alt +8 to jump back. You can move on to the next call.


Quickly find the Controller method


If you have a lot of controllers in your project, there are a lot of HTTP or resful methods in there. How do you quickly find these methods? This is where CTRL + Alt + Shift + N comes in handy.

For example, if you vaguely remember that the billing interface has a bill URL, press CTRL + Alt + Shift + N and type /bill.

This can be a huge productivity boost when you’re trying to find your way through thousands of controllers.


Bookmark is a great tool for understanding your project’s key business process methodology


In some startups, many of the core modules are placed in the same project. For example, order related interface, payment related interface, commodity related interface. At this point, you can place these key business methods in one place using Bookmark and make it easy for you to read.

So how do you use keyboard shortcuts to achieve this effect?

public class TestService {   public void test1() {       System.out.println("aa");   }   public void test2() {       test1();   }   public void test3() {       test1();       test1();   }}

Copy the code

For example, if I want to place test1() in bookmark, I can do the following: 1. Use CTRL + F12 to list all the methods in this class, then type test1 and place the cursor on test1. 2. Press F11 to add test1() to bookmark; 3. Hold down Shift + F11 to pop up the Bookmark list; 4. Press CTRL + Enter to change the bookmark name.


I’m just left with a TAB


This is the one I’m using right now, which is the one code TAB in the whole project. That is, no matter how many files you open, they are always displayed in the same TAB. If so, some users may ask, “I want to see which classes I have operated recently. What do you think?” You can use CTRL + E directly to display the most recently acted files.

I would recommend just keeping the code TAB, it’s very simple. If every time you open a file, it’s a new TAB, pretty soon you’re going to mess up, and you’re going to have to close some tabs.

You can set the code to display with a TAB as follows. Press CTRL +shif+a, then type Editor Tabs, and press Enter to go to the Edit page.

And then in Placement, select None


How to read long, smelly code


Because of history, projects have long, smelly business code that they don’t understand. Reading this code is a pain. But with IntellIJ IDEA, you can greatly improve your reading quality and speed by using just five tips.

Create arbitrary code collapse blocks


Like the for loop above, I want to fold it directly, because if the code is too long, using a collapse block can help you quickly sort out the main thread of your code.

You can position the cursor inside the open curly brace of the for loop and then use CTRL + Shift +. Can.

If you want the fold to disappear quickly, simply use CTRL +.


Curly bracket matching


This is also very useful because the code is so long that a for loop might fill the entire screen. At this point, it’s hard to find the other side of a brace. You can position the cursor next to a brace and use CTRL +] or CTRL +[to navigate back and forth.


CTRL + shift + f7 f3


CTRL + Shift + F7 highlights a variable, and the highlighting does not go away as the mouse moves (this is important). Then use F3 to find the next place to use the variable.


Use the CTRL + shift + I


This is also a great way to read long sections of code. If you want to see the definition of a class in the code, you can use CTRL + Shift + I to pop up another window in the current class. Such as:

 

In this code block, if you want to see the TestTemp class definition, place the cursor on TestTemp and press CTRL + Shift + I to bring up the following window.

Press ESC to close this window.


Use Alt + f7


I’ve already described this above. You can list where variables are used.

Combining these five techniques, I believe you can greatly improve the efficiency of reading long pieces of code.


Jump to the superclass interface


We often define a service interface, such as UserService, and then use a UserServiceImpl class to implement the interface in UserService.

public interface UserService { void test1(); }

Copy the code

public class UserServiceImpl implements UserService {   @Override   public void test1() {   }}

Copy the code

To jump to UserService test1() from test1(), use CTRL + U.


Regret medicine


If you change part of the code and suddenly feel that it does not fit, use CTRL + Z to roll back the code. All of a sudden, I think the modification is ok. Then you can use CTR + Shift + Z to restore the changes you just made.


Fastest way to switch skins


You can directly use CTRL, then add a ‘, will immediately pop up the following interface:

chooseColor SchemeAnd press Enter to pop up a window to modify the skin.

Further reading

IntelliJ IDEA Tutorial (2019 Edition) — From beginner to Addictive

IntelliJ IDEA Common shortcut keys

Recommended several IDEA plug-ins, Java developers luqiao code sharp tool

Intellij IDEA has these tips

Spring Boot configures those tips for random numbers

Source: https://blog.csdn.net/linsongbin1/article/details/80560332

Article source network, copyright belongs to the author, such as infringement of the rights of the original author, please contact us to delete