Cool Intellij IDEA Shortcuts

Search for a command to run...

Those are some great tips! I use Webstorm and occasionally IntelliJ at work. I love using Live Templates! It makes coding way faster. I like the idea of bookmarks so I’ll have to try that out.
Thanks for sharing!
Pods, Deployments and Services kubectl run nginx --image=nginx --port=80 kubectl run nginx --image=nginx --port=80 --expose=true kubectl run nginx --image=nginx --labels="app=web,tier=frontend" kubectl create deployment nginx --image=nginx kubectl c...

Elastic Beanstalk is one of the most powerful services powered by AWS for quick deployment and monitoring of your application. It provides a better and easiest way to auto-scale your application and balance workloads. In this article, I am not going ...

Software developers are not only responsible for writing codes, building, and testing applications. They must be responsible for avoiding security risks for the project and the company as a whole. Due to the growing use of the internet, applications,...

At the time of writing this article, there is no official support of Stripe for React-Native. I, having knowledge of backend, was trying to create RESTful endpoints to integrate Stripe payment using Spring boot. Although the documentation of Stripe i...

I have used Netbeans, Eclipse, STS, and Intellij IDEA but Intellij has been my first choice since my first use. It is one of the best IDE for developing applications. Compared to other IDEs, it provides strong support for autocomplete feature. The debugging feature in it is a lot easier and the User Interface is awesome. I just love it.
Using shortcuts helps us to do more in less time. I have my favorite IntelliJ IDEA shortcuts mentioned below.
Note: I have GNOME as a keymap setting in my IDE.
This is the most frequently used shortcut for me. It helps to rename the variables or methods names. Let’s see an example.
public List<String> getPaymentList(){
// logic
return Collections.emptyList();
}
Your senior developer didn’t like the name of your method or let’s say Uncle Bob would hate you for this method name which is why you would like to change it. It had been used in twenty different places and you have to replace the name manually. Can you feel the pain? Go to the method declaration part of your code or to the method calling part, place your cursor to the method name and hit Shift + F6, and rename your method. Voila, you can see the changes being reflected in all the files.
This is personally my favorite shortcut. It is also a shortcut to flex with junior developers. It helps us to multi-select the matching content. Consider the scenario, where you have this SQL file.
INSERT INTO users(id, name, address, phone) VALUES (1, 'John', 'ktm', '122233');
INSERT INTO users(id, name, address, phone) VALUES (2, 'Tim', 'ktm', '122234');
INSERT INTO users(id, name, address, phone) VALUES (3, 'Tom', 'ktm', '122235');
INSERT INTO users(id, name, address, phone) VALUES (4, 'Lindy', 'ktm', '122236');
INSERT INTO users(id, name, address, phone) VALUES (5, 'Catherina', 'ktm', '122237');
INSERT INTO users(id, name, address, phone) VALUES (6, 'Bill', 'ktm', '122238');
// 1000 of lines
You have to add one more column in this SQL called user_type with static value USER, are you going to do it manually? Definitely, not. There might be other options for this use case as well, but I am going to demonstrate the power of Alt + J. In the first line, place your cursor before VALUES and select phone) and hit Alt+J multiple times and you can see the exact word phone) being selected. This is what it looks like:
Move your cursor before ) and type , along with your column name i.e user_type. There you go, we unleashed the power of Alt + J. Also, we can unselect from the last by hitting Alt + Shift + J.
If you are working with multiple files, you might have to navigate between methods across different files. It will be a pain to go back and forth. Let’s say you are trying to fix a bug written by somebody else, you are already tired searching codes and you forgot the method name or class name you recently visited, it will be so infuriating. Adding a bookmark will help you to be more productive in such cases.
You can hit Ctrl+Shift+AnyKey to set a bookmark. For eg: Ctrl+Shift+1. Intellij IDEA will show a bookmark icon.
You can work with other files and if you feel like jumping into this code, you can hit Ctrl+AnyKey (Ctrl+1 in this case) and you will be returned to this method. It’s that easy. Similarly, you can remove the bookmark by hitting Ctrl+Shift+AnyKey.
I prefer deleting codes to writing codes. I love to refactor the code. This shortcut is used to inline the variable or method call. It’s mostly used while refactoring the code.
Customer customer = getCusomer();
createPaymentIntent(customer);
In the snippet like above, if it makes sense to you to inline getCustomer() method, then you can place your cursor to the customer object and hit Ctrl+Alt+N. It will inline the code and the result, then, looks like:
createPaymentIntent(getCusomer());
This shortcut also makes refactoring easy.
Snippet-1:
getCustomer(); //returns Customer Object
Select getCustomer() method and hit Ctrl+Alt+V to get the variable returned by the object. The result will be:
Customer customer = getCustomer();
Snippet-2:
Customer customer = new Customer();
customer.setName("Customer");
customer.setAddress("Ktm");
customer.setMobile("9779852365321");
Let’s say, you want to refactor this piece of code into a method. You can select these blocks of codes and enter Ctlr+Alt+M in order to extract to a method. Intellij IDEA will show a popup where you can enter the name of the method along with the visibility (access modifiers).
Likewise, Ctrl+Alt+P is for extracting the method parameter. Ctrl+Alt+C is for extracting a constant variable and Ctrl+Alt+F is for extracting a field variable.
You can save time by using live templates for the code blocks you use repeatedly. Intellij Idea itself provides some live templates. Let's check it out.
public static final snippet will be generated.public static final String snippet will be generated.throw new snippet will be generated.You can also define your custom live templates.
Thanks a lot for reading my article. If you know other cool shortcuts, then feel free to add in the comments :)