IntelliJ IDE Pro Tips and useful features
I have been a developer from last 10 years and have used a wide variety of IDEs ranging from Notepad ( Yes, I wrote my first java program in notepad !! ) to Netbeans. But when I started using Intellij , there is a visible difference in the way I used to work with Java projects. Unlike other IDE’s out there, this one is paid .But trust me , you will not regret the decision of paying for this IDE.
Intellij has got quite a bunch of usability options and features that you need to be aware of to make most of it. I am going to list some of them below. These are found from my own exploration and also from the help of other professionals who are using IntelliJ.
Find a file
You will be handling or having lot of files open in the IDE and finding the right one could be difficult. There are a bunch of shortcuts that will help you find the desired file within the project
Search for a Java class
If you are looking for a specific Java class name , you can search it by using :
Linux : [Ctrl] + [N]
Mac :[⌘] + [N]
This will only search for the Java class name and list the name
Search for a File name
If you are searching for a particular file by the name, you can search it by using:
Linux : [Ctrl]+ [Shift] + [N]
Mac : [⌘] + [Shift] + [N]
This will search for a file based on the name of the file.
Search for an item on the entire project
The above options only look in the project source files, but if you want to search on other locations like the dependent libraries, you need to use:
Linux : [SHIFT] [SHIFT] (Double shift)
Mac :[SHIFT] [SHIFT] (Double shift)
Source file navigation
When we have so many tabs open , its difficult to move to the previous one and then make some edit. There are some features of Intellij that can help us here.
A switcher allows you to move to a recently opened file. This is like the application switcher in the operating system. You can open the switcher using following keys:
Linux : [Ctrl] + [Tab]
Mac : [⌘] + [Tab]
The left hand side lists the different panels / tabs that you can open. Right side will list the files that are currently open in IDE and you can navigate using the arrows keys.
Recently opened files
If you only want to see the recently used files for the project, you can do so by pressing the following :
Linux : [Ctrl] + [E]
Mac : [⌘] + [E]
If you want to filter only by recently edited files only, then you can use the following variation:
Linux : [Ctrl] +[Shift] + [E]
Mac : [⌘] + [Shift]+ [E]
If you have multiple files open , you can move to the tab to the right using:
Linux : [Alt] + [Right arrow]
Mac :[Alt] + [Right arrow]
And to the left using:
Linux : [Alt] + [Left arrow]
Mac :[Alt] + [Left arrow]
If you want to have a split view of the screen, you can click on a tab and select ‘Split Vertically’ or ‘Split Horizontally’
Source code editing
Let’s see what are the shortcuts and features available when you are working on a source file .
Listing the methods in a class
Place the cursor inside anywhere in the class the use the following key combination:
Linux : [Ctrl] + [E]
Mac : [⌘] + [E]
You can start typing the letters to filter the methods by the typed letters.
One nice feature while editing source code is ability to have the source code progressively selected. For eg: if you place the cursor in a statement inside a ‘if’ condition, this will first select the statement, then the entire ‘if’ block, then the outer block of ‘if’ and so on.
Linux : [Ctrl] + [W]
Mac : [⌘] + [W]
To perform the reverese ( i.e, progressive de-selection), you can use the following key combination:
Linux : [Ctrl] + [Shift]+ [W]
Mac : [⌘] + [Shift]+ [W]
Template listing and code completion
There are built-in code templates in intellij that will generate snippets for you based on the variables selected. You can view the list by using the following combination:
Linux : [Ctrl] + [J]
Mac : [⌘] +[J]
Suppose, if you have a List variable, you can select it and use the template for creating a for-each loop for the selected variable from the templates listed.
To get a suggestion or code completion, we use the following key combination
Linux : [Ctrl] + [Space]
Mac : [⌘] +[Space]
But in case if we want to get a Smart Suggestion, we can use the following:
Linux : [Ctrl] + [Shift] + [Space]
Mac : [⌘] +[Shift] +[Space]
Suppose you are trying to get a suggestion for a return statement in a function, this shortcut will only display the variables that are matching the return type instead of showing all the types.
Now let’s see some miscellaneous features that we can use in Intellij apart from the one’s listed above.
Finding an action
Intellij has lot of actions and finding them at the right time from the menu or remembering the shortcut could be difficult. To help on this, we have an option to search for an action:
Linux : [Shift] + [Ctrl] + [A]
Mac :[Shift] + [⌘] +[A]
This will bring up a dialog where you can search for an action like ‘Run’ ,’build’ etc
Changing the theme
Lets see how we can change the theme of Intellij IDE. The default could be dark ( Darcula ) or normal ( Intellij )
Goto File -> Settings -> Search for Appearance and select the theme from the dropdown. You may need to restart the IDE to make it into full effect.
Paste from history
While editing the source code we may have used the copy command many times and when we paste, the last copied item is pasted. But there is an option to show the history of copied content and choose from that. Use the following command to view the history window.
Linux : [Shift] + [Ctrl] + [V]
Mac :[Shift] + [⌘] +[V]
Summing it up
We have seen several shortcuts in the post and here I am summing it up for your easy reference. Put it in a sticky notes and keep it handy 🙂
[⌘]/[CTRL] + [N] : Search for classes
DOUBLE [SHIFT] : Search all files
[⌘]/[CTRL] + [SHIFT] + [N] : Search any file
[⌘]/[CTRL] + E : Recently opened files
[⌘]/[Ctrl] +[TAB]:Switcher for all the open files
[⌘]/[CTRL] + [SHIFT] + E : Recent edited files only
[⌘]/[CTRL] + [F12] : Lists the methods in the current file
[⌘]/[CTRL] + [W] : Progressive select expand
[⌘]/[CTRL] +[SHIFT] + W : Progressive de-select
[⌘]/[CTRL] +[ J] : Opens the templates
[⌘]/[CTRL] + [SHIFT] + V : Open the history of copy
[⌘]/[CTRL] + [SSHIFThift] + [Space]: Smart auto complete suggestion
[⌘]/[CTRL]+ [SHIFT] + [A] : Search for an action
[⌘]/[CTRL]+ [SHIFT] + [V] : View the copy history for pasting
I hope someone finds these tips useful. Do let me know and share if you have something more to add 🙂
Roberto Cortez – Tip of the week : https://www.youtube.com/watch?v=FgNLuFt1g4w