Overview
Intellij IDEA
The more I use it, the more powerful it is. It always gives us a little surprise from time to time when we write code. Out Intellij IDEA
of love, I decided to write a column or series related to it to Intellij IDEA
share some useful techniques with you. This article is the first in this series, and mainly introduces some useful tips that you may not know about.
My Favorite【Show Mode】
We can use [Presentation Mode] IDEA
to maximize it, allowing you to focus only on the code in one class without any interference coding
.
You can use the Alt+V
shortcut key to pop up View
the view, and then select Enter Presentation Mode
. The effect is as follows:
The benefit of this pattern is that it allows you to focus more because you can only see the code for a specific class. Maybe readers will ask, after entering this mode, what should I do if I want to see the code of other classes? At this time, it's time to test your proficiency in shortcut keys. You can use CTRL+E
popup recently used files. Or use CTRL+N
and CTRL+SHIFT+N
locate files.
How to exit this mode? It's as simple as using the ALT+V
popup view and selecting Exit Presentation Mode
. But I strongly advise you not to do this, because you can do anything in the Enter Presentation Mode
modal . IDEA
Of course, the premise is that you IDEA
are skilled enough.
Magical Inject language
If you use it IDEA
when writing JSON
strings, and then have \
to escape the double quotes one by one, it is really inappropriate, annoying and error-prone. You IDEA
can use Inject language
help us to escape double quotes automatically.
First locate the focus inside the double quotation marks, use the alt+enter
shortcut key to pop up inject language
the view, and select it Inject language or reference
.
After selecting, remember to directly press the enter
Enter key to pop up the inject language
list. Select json
Components .
After selecting. The mouse focus will automatically be positioned inside the double quotation marks. At this time, you alt+enter
can see it when you use it again.
Select Edit JSON Fragment
and press Enter, you can see JSON
the view of editing the file.
You can see that IDEA
it does help us to automatically escape the double quotes. If you want to exit JSON
the view of editing information, just use the ctrl+F4
shortcut key.
Inject language
The number of languages and operations that can be supported is unimaginable, and readers can study by themselves.
Use shortcut keys to move dividing lines
Suppose there is the following scenario, the name of a class project
is blocked by a certain part in the view.
You want to see the full class name, what to do. Generally, the mouse is used to move the dividing line, but this is too inefficient. You can use alt+1
the mouse focus to position the project
view, and then use it directly ctrl+shift+左右箭头
to move the dividing line.
ctrl+shift+enter is not just for adding semicolons at the end of lines
ctrl+shift+enter
In fact, it 为您收尾
means that it is not just used to add semicolons to the code. For example:
In this code, we also need to add curly brackets to the if statement to compile and pass. At this time, if you enter it directly ctrl+shift+enter
, IDEA
it will automatically end it for you and add curly brackets.
Don't use IDEA's refactoring feature at every turn
IDEA
The refactoring function is very powerful, but sometimes, in a single class, if you just want to modify a certain text in batches, you don't need to use the refactoring function. For example:
In the above code, rabbitTemplate text is used in 5 places. How to modify it in batches? The first is to use the ctrl+w
selected rabbitTemplate
text, and then use the alt+j
shortcut keys 5 times in turn to select one by one, so that the five texts are all selected and highlighted. At this time, you can directly modify them in batches.
remove navigation bar
Remove the navigation bar, because it is not often used.
You can remove the red navigation bar to make it IDEA
look more clean and tidy. use alt+v
and then remove Navigation bar
. After removing this navigation bar, if you still use it occasionally, alt+home
you can temporarily display the navigation bar by using it directly.
If you want this temporary navigation bar to disappear, just use the esc
shortcut key.
Position the mouse in the project view
When there are many packages and classes in the project, sometimes we want to know where the current class is in the project view.
In the picture above DemoIDEA
, how do you know where it is in the spring-cloud-config
project? You can use it first alt+F1
, pop up the Select in
view, and then select Project View
the one in the middle Project
, press Enter, and you can immediately locate the location of the class.
So how do you project
jump back into the code? You can use the esc
exit project
view directly, or use it directly F4
and jump into the code.
powerful symbol
If you vaguely remember a few letters of a method name and want to IDEA
find it out, what can you do? Use directly ctrl+shift+alt+n
, use symbol
to find. For example:
You want to find the checkUser method. Just enter it directly user
.
If you remember that there is a method in a business class, you can also use the first letter to find the class, then add one .
, and then enter the method name.
how to find the directory
After use ctrl+shift+n
, use /
, and then enter the directory name.
Automatically generate not null judgment statement
IDEA
There are many ways to automatically generate the if judgment of not null , one of which you may not have thought of.
When we use rabbitTemplate., just enter it directly notnull
and press Enter, then IDEA
the if judgment will be automatically generated.
Find content by template
This is also a feature I like very much, which can find code blocks that match the template based on the template. For example:
I want to find all try catch statements in the whole project, but there is no exception handling in the catch statement.
Not handling exceptions in catch statements is extremely dangerous. We can IDEA
easily find all such code inside.
First use the ctrl+shift+A
shortcut key to pop up the action box, then enterSearch Struct
After selecting Search Structurally
, press Enter to jump to the template view.
Click Existing Templates
the button to select a try
template. In order to find out the code block in the catch that does not handle the exception, we need to configure CatchStatement
the Maximum count
value of , and set it to 1.
Click the button to modify the value Edit Variables
in the interface .Maximum count
Finally, by clicking find
the button, you can find out the code that does not handle the exception in the catch.