Are you making the most of IntelliJ IDEA to speed up basic code editing? You’d be surprised how many time saving shortcuts are available for basic navigating, highlighting, and moving code in the editor.
Here’s a run-through of the 13 most important, with both Windows and Mac shortcuts. How many of these shortcuts do you know?
Jump to editor to start coding
How do you actually get to the editor in IntelliJ IDEA?
Wherever you are in the IDE, just hit Escape
to move focus to the editor. Much quicker than using a mouse!
If you see an empty screen, then you just need to open a class. Hit Ctrl + N
and enter the class name.
Navigate your code faster
Now you’re ready to code, but how to navigate around? You could point and click, but that wastes time moving your hand away from the keyboard.
Better to use the arrow keys for fine grained control of the caret position.
Or to skip entire words hold Ctrl
as you press ←
and →
arrow keys.
You can also hit Home
to jump to the start and End
to the end of a line.
Yes, there’s a reason these keys all hang out together on the keyboard. Use them!
Let’s say you’ve got a larger class and need to jump between methods.
That’s easy with Alt + ↑
for previous, and Alt + ↓
for next methods.
Another option is Ctrl + F12
which shows the class structure. Hit the ↑
and ↓
arrows to choose the method, then enter to navigate to it.
Quick code selection
To select a portion of a line that maybe you want to replace, delete, or copy, hold down Shift
and press ←
or →
arrow keys.
And hold down Ctrl
as you do that to jump entire words.
Another way to select text is with Ctrl + W
, IntelliJ IDEA’s extend selection tool. It progressively selects more and more code.
By the way, whatever selection you have, just hit Escape
, ←
, or →
to deselect it and continue.
Copy a line like a pro
But whatever you do, don’t highlight a whole line to copy and paste it. Way too slow! Instead, there’s a keystroke-killing shortcut, Ctrl + D
. It copies the line your caret is on.
Just remember D for duplicate.
And opposite is Ctrl + Y
to delete a line. Nice!
Bulk move code
A common situation is when a line of code is in the wrong place. No need for cut and paste. Instead, hold Ctrl
, Shift
and use the ↑
and ↓
arrows to move the line.
You can even do the same thing with multiple lines at once!
Get me out of here!
And remember, if at any time you make a mistake just hit Ctrl + Z
to undo.
And then when you realise you actually didn’t make a mistake, Ctrl + Shift + Z
to redo.
Powerful bonus tip
OK, you probably knew that one. Here’s a bonus tip then. It’s a powerful one, so be careful. 💪
Highlight some text using the techniques mentioned earlier, then hit Alt + J
. This additionally selects the next occurrence of the text. Press again to select more occurrences.
You can even make edits in multiple positions at the same time. I did say it was powerful!
When you’re done, hit Escape
to get out of that mode and back to dry land.
Shortcut summary table
Shortcut name | Windows shortcut | Mac shortcut |
---|---|---|
1. Go to editor | Esc | Esc |
2. Go to class | Ctrl + N | ⌘ O |
3. Skip word | Ctrl + ←/→ | ⌥ + ←/→ |
4. Line start / end | Home / End | Fn ← / Fn → |
5. Previous / next method | Alt + ↑ / Alt + ↓ | ⌃ ↑ / ⌃ ↓ |
6. File structure popup | Ctrl + F12 | ⌘ F12 |
7. Simple select text | Shift + Arrow Key | Shift + Arrow Key |
8. Extend selection | Ctrl + W | ⌥ ↑ |
9. Duplicate line | Ctrl + D | ⌘ D |
10. Delete line | Ctrl + Y | ⌘ Delete |
11. Move statement | Ctrl + Shift + ↑/↓ | ⇧ ⌘ ↑/↓ |
12. Undo | Ctrl + Z | ⌘ Z |
13. Redo | Ctrl + Shift + Z | ⇧ ⌘ Z |
Bonus: Next occurrence | Alt + J | ⌃ G |
Resources
Stop reading Gradle articles like these
This article helps you fix a specific problem, but it doesn't teach you the Gradle fundamentals you need to actually help your team succeed.
Instead, follow a step-by-step process that makes getting started with Gradle easy.