JavaRush /Java Blog /Random EN /IntelliJ IDEA User Guide: More Hotkeys!
Level 9

IntelliJ IDEA User Guide: More Hotkeys!

Published in the Random EN group
Memorizing all key combinations in IDEA is a bad idea. You will not immediately use all the possibilities, and because of the mess in your head, you can confuse the new combinations that you would like to apply. In addition, after a while, when you need knowledge that has already been covered with a thick layer of dust, about unused combinations, you simply won’t remember them. Therefore, in this article I will try to describe those combinations that I use quite often (I hope they help not only me, phew). And so let's go! ;) Everyone had a situation when: "I need to copy this piece, but there is also a necessary thing in the buffer" In this situation, Ctrl + D comes to the rescue This is a line copy command (a piece of a line, a piece of class code, and whatever you want that can be selected in a file), while it copies the code to the same line where the "selection cursor" ends. Therefore, if you want to copy to the next line, grab it too =) IntelliJ IDEA User Guide: More Hotkeys!  - 1
IntelliJ IDEA User Guide: More Hotkeys!  - 2
When you don’t really want to delete any piece of code, but placing a comment on many lines is not very convenient. There are shortcuts for this case: Ctrl + / Ctrl + Shift + / In the first option, you will comment out a piece of code - a single-line comment: IntelliJ IDEA User Guide: More Hotkeys!  - 3 In the second option, the comment will be many lines:
IntelliJ IDEA User Guide: 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, delete it or you can somehow rename it. You can rename it! To do this, you can right-click on the name of the class in the project: IntelliJ IDEA User Guide: 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 to delete 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 with some kind of block (if / for / try and all that), you will be saved: Ctrl + Alt + T IntelliJ IDEA User Guide: More Hotkeys!  - 6 A useful combination, to clean up the code: Ctr + Alt + I It equalizes 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 Guide: More Hotkeys!  - 7 After:
IntelliJ IDEA User Guide: More Hotkeys!  - 8
(Spoiler alert!) But there is an even more powerful thing! which not only changes lines, but also brings your code in line with the code style: Ctr + Alt + L This will definitely teach you how to program beautifully! IDEA also understands some abbreviations, which it will later convert to full commands. Here are some that might come in handy: 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++){} You can see all the abbreviations with: Ctrl + J Oh yes, I almost forgot about the most useful thing in IDEA! If suddenly a blunder happens! Maybe it's not big, but it's nasty and... In short, the program won't start =) Surely you've had cases when some mistakes were made while writing in the code and IDEA underlined the place of the error in red. And you sit like that and think: "What a devil! She doesn't like something again! But right there everything is fine!" To understand what she doesn’t like, you need to put 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 Guide: More Hotkeys!  - 9