JavaRush /Java Blog /Random EN /IntelliJ IDEA User Guide: Keyboard Shortcuts

IntelliJ IDEA User Guide: Keyboard Shortcuts

Published in the Random EN group
Hello! In this article I will tell you about shortcuts. There will be many pictures and if there are several of them, then the first one is before, and the next ones are after pressing the shortcuts. I hope it will be easy and informative.
IntelliJ IDEA User Guide: Hotkeys - 1
Hotkeys in IntelliJ IDEA are a very powerful weapon that many people underestimate. When used confidently, they can increase development speed by an order of magnitude. The full list of existing ones can be viewed by pressing Alt+h+k. Therefore, below there will be a screenshot of my idea and I will tell you about those that I use more often than others. At the end I will show you how to write your own shortcuts. Go!)
IntelliJ IDEA User Guide: Hotkeys - 2
This is my development environment, but not a working one, here I learned Spring and checked code examples, so I used it extremely rarely, however, in half a year the shortcuts saved me from writing 17 thousand characters. A good enough argument to start using them, isn’t it?) I’ll go in order: Ctrl + Space – shows a list of options with which you can complete the input.
IntelliJ IDEA User Guide: Hotkeys - 3
Ctrl + w – smart text selection. First, it selects the word where the cursor is, and then the nearest commands, and so on up to the entire document.
IntelliJ IDEA User Guide: Hotkeys - 4
IntelliJ IDEA User Guide: Hotkeys - 5
IntelliJ IDEA User Guide: Hotkeys - 6
IntelliJ IDEA User Guide: Hotkeys - 7
Ctrl + y – deletes an entire line, while keeping the cursor at the same position.
IntelliJ IDEA User Guide: Hotkeys - 8
IntelliJ IDEA User Guide: Hotkeys - 9
Ctrl + Shift + Space – same as Ctrl + Space , only takes into account static fields and methods. It also helps to initialize the field with the appropriate type.
IntelliJ IDEA User Guide: Hotkeys - 10
IntelliJ IDEA User Guide: Hotkeys - 11
Ctrl + b – goes to the declaration of a field, method or cash register. Same effect as pressing Ctrl + LMB
IntelliJ IDEA User Guide: Hotkeys - 12
IntelliJ IDEA User Guide: Hotkeys - 13
Ctrl + / - comments a line of code; if you select several lines, it will comment out all of them.
IntelliJ IDEA User Guide: Hotkeys - 14
IntelliJ IDEA User Guide: Hotkeys - 15
Shift + F6 – Renames a field, method or class in all places where it is used.
IntelliJ IDEA User Guide: Hotkeys - 16
Now let me tell you in detail how to create your own shortcut. We need to get into the settings, this is done with the combination Ctrl+Alt+s and go to Keymap:
IntelliJ IDEA User Guide: Hotkeys - 17
And then we select what we need to install the shortcut on, press RMB and select the combination.
IntelliJ IDEA User Guide: Hotkeys - 18
I set the combination Shift+Alt+e to delete everything to the right of the cursor on the selected line.
IntelliJ IDEA User Guide: Hotkeys - 19
Now we check that everything works and move on.
IntelliJ IDEA User Guide: Hotkeys - 20
IntelliJ IDEA User Guide: Hotkeys - 21
This particular shortcut looks very useless, but you have a free combination and know how to do it, you can use it on what you need. At work I use it for Annotate, it is needed to work with Git and shows who made changes to the code and when. Now let's talk a little about autofill. What it is? This is the ability to enter several words or even a block of code with one abbreviation. Example: Instead of manually entering the empty main method, you can use the first letters of these words:
IntelliJ IDEA User Guide: Hotkeys - 22
There are many similar key combinations and, for example, I haven’t manually entered a loop for a long time ( iter or itar ). You can create one for the most popular variable declarations and it will save a lot of time in the future. This is done like this: go to settings ( Ctrl + Alt + s ) and select Editor, then Live Templates.
IntelliJ IDEA User Guide: Hotkeys - 23
IntelliJ IDEA User Guide: Hotkeys - 24
Select the “other” category and click on the green plus sign on the right or use the Alt+Insert shortcut, then “Live Template”. Set the abbreviation, description and definition for our personal autofill form. For now you can just follow the example to figure it out, redoing it later won’t be difficult)
IntelliJ IDEA User Guide: Hot Keys - 25
Click Define, check the “Everywhere” box, save and check.
IntelliJ IDEA User Guide: Hotkeys - 26
IntelliJ IDEA User Guide: Hotkeys - 27
And finally, there is such a combination as Ctrl + Alt + t - it wraps the selected command in a block of code
IntelliJ IDEA User Guide: Hotkeys - 28
IntelliJ IDEA User Guide: Hotkeys - 29
So, we can write such a command ourselves. For example, I want to wrap the code in System.out.println(); press Ctrl + Alt + t and select the very last item
IntelliJ IDEA User Guide: Hotkeys - 30
Last time we selected “other”, now click on “surround”, Alt+Insert , then Live Templates, enter the data shown in the picture below and save.
IntelliJ IDEA User Guide: Hotkeys - 31
Now we use our template. We select what we want to output to the console, press Ctrl+Alt+t , then what we entered in the Abbreviation field (the fewer characters there, the better), in our case it’s S , and we got it.
IntelliJ IDEA User Guide: Hotkeys - 32
IntelliJ IDEA User Guide: Hot Keys - 33
You just have to remove the semicolon at the end before the parenthesis. In my work, I try to use shortcuts as often as possible and I believe that good knowledge of your development environment will not only set you apart from other developers, but will also significantly improve productivity. Thank you for your attention, I will be glad to hear your feedback!)
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION