Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

IntelliJ IDEA - Small tips with big value

DZone's Guide to

IntelliJ IDEA - Small tips with big value

·
Free Resource
This time I'd like to share a couple of little tips on using IntelliJ IDEA, which can make your coding more productive and enjoyable at the same time. However small they may look at first, they are likely to have a huge impact on your performance and enjoyment over time. At least, they have had such an effect on me.

Method separators

Let's start with something simple. Having methods visually separated by a horizontal line helps code readability.


If you want to have the methods visually separated, go to the settings with Control + Alt +S, immediately start typing what we're looking for - "sepa..."

and see how the dialog gradually limits its content to show only the relevant entries in the settings. Check the checkbox for "Show method separators" and you're ready to go.

And as for the tip regarding text search inside the settings dialog - take it as a free bonus tip.

Invoke action by name

Following on the same wave, the proven wisdom goes that search is faster than a look-up. IDEA allows you to invoke commands like refactorings or code generation by name (or just a part of it). To see the magic, choose a block of code worth refactoring and instead of going up into the menu press Control + Shift + A and enter the name of the command you want to perform. Wild cards or incomplete names are of course allowed.

Faster than scanning the menu, I'm certain.

Go To Symbol

The last example of the same search-over-navigation principle. Searching for a method or a variable you only know a name of or a part of it, but can't remember in which file/class it is defined? The Control + Alt + Shift + N key shortcut is a quick way to search for such an element in your project.

No matter how deep it has hid, you'll get it.

 

Highlight element at caret

This is a feature I've gradually grown into liking. Having all occurrences of the element you're looking at instantly highlighted in the editor can be a great help for some.

Not surprisingly, the feature works equally well in other supported technologies, like e.g. HTML or JavaScript. To turn the feature on, press Control + Alt + S to open the settings dialog, search for "Highlight usages of element at caret" and check the checkbox.

Done.

Block selection

Copying a block of code or applying a refactoring requires you to select a piece of code for these actions to operate on. Using Control + W to expand selection around caret and Control + Shift + W to shrink it you make sure you always select a semantically valid block of code.

It is as easy as that, in all supported languages, not only Java.

Compare with clipboard

The last trick for today: now when you know how to effectively select a block of code, how about comparing it with the snippet you've just received from your colleague by email? Or with the class in the org.project.used.but.unmainteintable package? IDEA allows you to quickly compare a selected block of code with the content of the clipboard. In fact it goes further than that. You get a complete merge tool, allowing you to make changes to your code or copy and remove distinct pieces of code as blocks.

Refreshing the knowledge from earlier, remember the shortcut for invoking a command by name?

[Control + Shift + A, you're correct]

And here's the merge tool:

Conclusion

These were some of the small shiny productivity pearls I wanted to show today. What are your favorite little IDEA tricks? Let others know in the discussion!

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}