Intellij IDEA artifact actually has these little tricks

Overview


Intellij IDEAThe 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 IDEAof love, I decided to write a column or series related to it to Intellij IDEAshare 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] IDEAto maximize it, allowing you to focus only on the code in one class without any interference coding.

You can use the Alt+Vshortcut key to pop up Viewthe view, and then select Enter Presentation Mode. The effect is as follows:write picture description here

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+Epopup recently used files. Or use CTRL+Nand CTRL+SHIFT+Nlocate files.

How to exit this mode? It's as simple as using the ALT+Vpopup view and selecting Exit Presentation Mode. But I strongly advise you not to do this, because you can do anything in the Enter Presentation Modemodal . IDEAOf course, the premise is that you IDEAare skilled enough.


Magical Inject language


If you use it IDEAwhen writing JSONstrings, and then have \to escape the double quotes one by one, it is really inappropriate, annoying and error-prone. You IDEAcan use Inject languagehelp us to escape double quotes automatically.write picture description here

First locate the focus inside the double quotation marks, use the alt+entershortcut key to pop up inject languagethe view, and select it Inject language or reference.write picture description here

After selecting, remember to directly press the enterEnter key to pop up the inject languagelist. Select jsonComponents .write picture description here

After selecting. The mouse focus will automatically be positioned inside the double quotation marks. At this time, you alt+entercan see it when you use it again.write picture description here

Select Edit JSON Fragmentand press Enter, you can see JSONthe view of editing the file.write picture description here

You can see that IDEAit does help us to automatically escape the double quotes. If you want to exit JSONthe view of editing information, just use the ctrl+F4shortcut key.

Inject languageThe 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 projectis blocked by a certain part in the view.write picture description here

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+1the mouse focus to position the projectview, 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+enterIn fact, it 为您收尾means that it is not just used to add semicolons to the code. For example:write picture description here

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, IDEAit will automatically end it for you and add curly brackets.


Don't use IDEA's refactoring feature at every turn


IDEAThe 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:write picture description here

In the above code, rabbitTemplate text is used in 5 places. How to modify it in batches? The first is to use the ctrl+wselected rabbitTemplatetext, and then use the alt+jshortcut 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.write picture description here


remove navigation bar


Remove the navigation bar, because it is not often used.write picture description here

You can remove the red navigation bar to make it IDEAlook more clean and tidy. use alt+vand then remove Navigation bar. After removing this navigation bar, if you still use it occasionally, alt+homeyou can temporarily display the navigation bar by using it directly.write picture description here

If you want this temporary navigation bar to disappear, just use the escshortcut 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.write picture description here

In the picture above DemoIDEA, how do you know where it is in the spring-cloud-configproject? You can use it first alt+F1, pop up the Select inview, and then select Project Viewthe one in the middle Project, press Enter, and you can immediately locate the location of the class.

write picture description here

So how do you projectjump back into the code? You can use the escexit projectview directly, or use it directly F4and jump into the code.


powerful symbol


If you vaguely remember a few letters of a method name and want to IDEAfind it out, what can you do? Use directly ctrl+shift+alt+n, use symbolto find. For example:write picture description here

You want to find the checkUser method. Just enter it directly user.write picture description here

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.write picture description here


how to find the directory


After use ctrl+shift+n, use /, and then enter the directory name.write picture description here


Automatically generate not null judgment statement


IDEAThere are many ways to automatically generate the if judgment of not null , one of which you may not have thought of.write picture description here

When we use rabbitTemplate., just enter it directly notnulland press Enter, then IDEAthe if judgment will be automatically generated.write picture description here


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 IDEAeasily find all such code inside.write picture description here

First use the ctrl+shift+Ashortcut key to pop up the action box, then enterSearch Struct write picture description here

After selecting Search Structurally, press Enter to jump to the template view.write picture description here

Click Existing Templatesthe button to select a trytemplate. In order to find out the code block in the catch that does not handle the exception, we need to configure CatchStatementthe Maximum countvalue of , and set it to 1.

Click the button to modify the value Edit Variablesin the interface .Maximum countwrite picture description here

Finally, by clicking findthe button, you can find out the code that does not handle the exception in the catch.write picture description here


Original link


Intellij IDEA artifact actually has these little tricks

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325965818&siteId=291194637