Tuesday, March 8, 2016

12 IntelliJ IDEA Keyboard Shortcuts, mandatory to know!

intellij-idea-shortcuts-small

1. (Un)Comment line: Cmd + L

Transforming the current line into comment is essential in bug tracking. Instead of going to the beginning of line and manually typing //, Cmd+L will do that for us. Even cooler, the editor will know how to uncomment lines, even when commented out manually. A good thing to know is that caret will move to the next line automatically, allowing multiple lines to be commented out at once.
Line comment

2. (Un)Comment selection: Shift + Control + /

Similar to line commenting, this shortcut will surround the current selection. While line commenting is quicker, here you can be much more precise and more creative with comments. Refer to the figure below for comparison.
Selection comment

3. Documentation comment block: /** + Enter

Not quite a keyboard shortcut, this one is more of a code completion helper. After you create a member, go one line above it and type /** followed by a press on the Enter key. Voila, IDEA will automagically create a documentation block for you. If you place it above a method, the block will be populated with argument params, which can be tremendously useful.
EDIT: Denis Zhdanov of JetBrains pointed out a great new feature shipped as of v12, “Fix Doc Comment”. Read more about it here on his blog post.
I don’t think I can stress the importance of documentation in code. Please use line comments and documentation blocks as much as possible. They will help you more than you can imagine, others even more.
Documentation block

4. Delete line: Cmd + Y

Another no-brainer very useful. No need to get your hands off of keyboard to reach for the mouse, or use extra shortcuts to select a line + Backspace. Simply place caret at the line you want out of your project and push Cmd + Y.
Here’s how I remember that it’s Y and not another key, D for example. You know how deletions are frequently followed by a confirmation dialog? “Are you sure you want to delete this item?” and similar. Most of us have trained our eyes to find a short little word that begins with an Y – Yes. Here we’re skipping the dialog and agreeing immediately. Yes, delete the sucker!

5. Argument documentation for method calls: Cmd + P

Useful when you need to remember argument options when calling a method, this shortcut will pull up a callout with the information you need. It is even capable of learning from your documentation blocks.
Parameter callout

6. Incremental selection: Cmd + W

Although Cmd + W defaults to close tab/window in most applications (and so it did in IDEA < 11), IDEA 11 and up assigned to to a whole new purpose.  When you need to select a word, reference, statement, line, or entire block of code without lifting your hands from keyboard, this shortcut comes to the rescue. Press it once to select the word closes to the caret. Repeat to incrementally select larger chunks.
Incremental selection

7. Reformat code: Option + Cmd + L

Whether you are a fan of JSLint or you follow another JavaScript code style, you can configure IDEA to learn it and reformat your code accordingly. First, make sure you’re satisfied with settings found at Preferences -> Code Style – > Your Language. Walk through the tabs offered and set the style that best match your desired behavior. Once completed, go to your code.
Pressing Option + Cmd + L will politely ask you which section you want to reformat. It can be a selection, file, or even entire project.
In some situations, you may need to omit parts of code (e.g. when concatenating arrays of html strings). In such case, selecting a code area and hitting the shortcut will automatically offer to reformat selection. So hit shortcut and press enter for a quick and smart code reformat.

8. Cycle through the history of most recent changes: Cmd + Shift + Backspace

When editing huge files, and I mean many at the same time, it can get difficult to navigate through the maze of code. The effect is stronger when editing someone else’s code. In such situations, I find this shortcut very useful. It doesn’t delete anything, as Backspace may imply, it just shifts the caret over to the position of last change. It goes like that long ways through history, and even switches open files for you. If you haven’t already, try it out, it’s a gem.

9. Paste from five previous copies – Cmd + Shift + V

Does the OS default one slot in memory for copy-paste satisfy you? IDEA tracks your last five copies and allows you to chose from them when pasting. Instead of the accustomed Cmd + V for paste, add Shift to the combination and a dialog pops up, offering the options.
Paste history

10. Find members in current file: Cmd + F12

Easily on of my top three favorite shortcuts, this one emulates Cmd + Shift + O in Chrome Inspector. Basically, it shows a popup with all objects and respective members associated with a file. Moreover, if you start typing, it will perform a search and select the line you were looking for. Amazingly useful in big files.
As an added bonus, press the shortcut twice to show the inherited members.
Find members
If you can’t reproduce this on a Mac, make sure F12 (Fn + F12) is not registered to Mission Control. Simply go to OS X’s Settings -> Mission Control and remove any existing bindings. Now you can retry in IDEA.
Disable F12 in Mission Control

11. Find members in current project: Cmd + Alt + Shift + N

Finding members in a file is quick and easy. Alternatively, if you want to find members throughout the project, sacrificing just a tiny bit of speed, then this shortcut is meant for you.
Find members in a project

12. Show recently changed files: Cmd + Shift + E

IDEA will automatically manage your tabs so that you don’t have too many to clutter your workspace. In many workspaces, you might also want to close the project browser window in order to save some horizontal space. Getting to see the most recently edited files is a speed boost that will help any developer working in a similar environment. Just press Cmd + Shift + E and chose from the list, sorted in ascending order relative to the time of last edit. Guess what – it even works after you restart the editor!
Recent Edits
Note on automatic tab management: IDEA will auto close tabs to keep the workspace tidy. This action will not result in losses such as file state, undo/redo stack, or even scroll position. If, for any reason, you may want to keep a tab constantly visible, right click on it and select ‘Pin active tab’. I’m afraid here isn’t a default shortcut for pinning tabs.


1 comment:

  1. in this current digital world, students do no longer want to go physically to writing specialists one by one and meet them to spend whole day. Now, they just need to discover a right writing experts just like the actuarial exam dot com. Key Switches

    ReplyDelete