JavaRush /Java Blog /Random EN /IntelliJ IDEA User's Guide: Some more hotkeys!
Level 9

IntelliJ IDEA User's Guide: Some more hotkeys!

Published in the Random EN group
Memorizing all the key combinations in IDEA is a bad idea. You won’t be able to use all the possibilities right away, and because of the confusion in your head, you may confuse new combinations that you would like to use. Moreover, after some time, when you need knowledge that is already covered with a thick layer of dust, about unused combinations, you simply will not remember them. Therefore, in this article I will try to describe those combinations that I use quite often (I hope they will help not only me, phew). And so let's go! ;) Everyone has had a situation when: “I need to copy this piece, but there is also a necessary thing in the buffer.” In this situation, it comes to the rescue: Ctrl + D This is a command for copying a line (a piece of a line, a piece of class code, and whatever you want , which can be selected in the file), and it copies the code to the same line where the “selection cursor” ends. So if you want to copy to the next line, grab that too =) IntelliJ IDEA User's Guide: Some more hotkeys!  - 1
IntelliJ IDEA User's Guide: Some more hotkeys!  - 2
When you don’t really want to delete any piece of code, but placing comments on many lines is not very convenient. There are keys for this in real life: Ctrl + / Ctrl + Shift + / In the first option, you will comment out a piece of code with a one-line comment: IntelliJ IDEA User's Guide: Some more hotkeys!  - 3 In the second option, the comment will be multi-line:
IntelliJ IDEA User's Guide: Some more hotkeys!  - 4
(Spoiler: you can also remove a comment using these combinations) Or it may happen that you described yourself in the name of the class, and then you think about deleting it or renaming it somehow. You can rename it! To do this, you can right-click on the name of the class in the project: IntelliJ IDEA User's Guide: Some more hotkeys!  - 5 Or on the name in the class itself (select the same menu positions). But! As you saw in the screenshots, there is a small hint for the keyboard shortcut: Shift + F6 There is also a function for deleting a line without selecting it. The main thing is that there is a cursor there, the rest is details =) Ctrl + Y If you have code, but you need to wrap it in some kind of block (if / for / try and all that), you will be saved: Ctrl + Alt + T IntelliJ IDEA User's Guide: Some more hotkeys!  - 6 A useful combination, to restore order in the code: Ctr + Alt + I It aligns the indents in the code (if a piece of code is selected, then in this piece, if not, on the line where the cursor is). Example before: IntelliJ IDEA User's Guide: Some more hotkeys!  - 7 After:
IntelliJ IDEA User's Guide: Some more hotkeys!  - 8
(Spoiler alert!) But there is something even more powerful! which not only changes lines, but also brings your code into compliance with the code style: Ctr + Alt + L This will definitely teach you how to program beautifully! IDEA also understands some abbreviations, which it later converts into full commands. Here are some that may be useful: psvm + tab -> public static void main sout + tab -> System.out.println() serr + tab -> System.err.println() I + Enter -> for(Object object : ){} + ESC iter + Enter -> for(Object o: ){} + ESC fori + tab -> for (int i = 0; i < ; i++){} All abbreviations can be viewed using: Ctrl + J Oh yes, I almost forgot about the most useful thing in IDEA! If suddenly a mistake happens! Maybe it’s not big, but it’s nasty and... In short, the program won’t start =) Surely you’ve had cases when you made some mistakes when writing the code and IDEA underlined the place of the error in red. And you sit there and think: “What a devil! Again she doesn’t like something! But everything is fine right there!” To understand what she doesn’t like, you need to place the cursor in the place where she highlights and press the combination: Alt + Enter After that, she will offer her solution, you can choose from this list (she offers very smart things), in rare cases you will have to think for yourself . IntelliJ IDEA User's Guide: Some more hotkeys!  - 9