Yext is primarily a Java shop—aside from a smattering of Go, all of our backend systems are written in Java. For a long time we used Eclipse, which was the standard IDE at the time. Over the past few years, however, the vast majority of Yext engineers have moved to using IntelliJ (it’s now our default IDE).1 In this post, I’ll share a few of the IntelliJ features and hotkeys that I find myself using all the time.

These features (and many more) are mostly listed as part of IntelliJ’s default keymap. I’ll be referring to the Mac OS X 10.5+ keymap throughout this post, which is not the default Mac keymap. You can set your keymap shortcuts via the IntelliJ preferences.

Also, in case you can’t remember the Mac keyboard symbols (I never do), here they are:

Symbol Key
command
shift
control
option
return

Enjoy!

Navigation

Go To Declaration (⌘B, ⌘Click)

This is probably the most useful hotkey for navigating code. When your cursor is on a method call (or variable, or class name), using go to declaration will take you to where that item is defined. It also works the other way—if your cursor is at a method declaration, this hotkey will show you where that method is being used.

Back / Forward (⌘[ / ⌘])

Tired of losing your place in the code base? This is easily fixed with the navigate back / forward hotkeys, which function similarly to how you navigate back / forward in a web browser.

Go To File (⌘⇧O)

This lets you search for a file to open. You can also use go to class (⌘O) if you’re looking for java files.

File Structure Popup (⌘F12)

This popup shows all the methods and fields in the class you’re currently in. There are some settings you can configure at the top of the popup to filter and sort the results you see.

Editing

Intention Actions and Quick Fixes (⌥↩)

IntelliJ has a number of helpful suggestions to optimize and clean up your code. You can see and apply its suggestions with this quick fix hotkey.

Reformat Code (⌘⌥L)

It’s easy for your code to get messy during development. You end up with long lines, awkward indentations, etc. When it’s time to clean things up, just select the lines you want to change and reformat. IntelliJ will reformat based on your configured code style (Preferences > Editor > Code Style).

Optimize Imports (⌃⌥O)

If you don’t have a tool to fix your imports automatically, you can use IntelliJ’s optimize imports. It removes any extra imports and rearranges the remaining imports as defined by your code style.

Multicursor

Sometimes you need to make some rote, identical changes. For example, suppose you’re initializing a constructor:

public MyConstructor(
    String var1,
    String var2,
    int var3)
{
    ...
}

You need to set all of the class’s fields, i.e. all of the this.var1 = var1; lines. This is trivial with multicursor! As the name implies, you can use multiple cursors to (in this case) copy all three variable names at once. It’s then really easy to paste and edit as needed. This is similar to Multiple Selections in Sublime Text.

To actually place additional cursors, you can use ⌥⇧Click. Alternatively, you can press twice and, while holding it, press the up or down arrow keys.

Refactoring

Of all the hotkeys in this post, the refactoring hotkeys are probably my favorites. Our code constantly gets refactored, and these hotkeys let us do these refactorings faster and with less human error.

Rename (⇧F6)

As code changes, the names of your variables, methods, and classes will often drift from their intended purpose. Renaming makes it easy to keep names up to date.

You can also use renames to combine existing method calls. Suppose you want to get rid of a method, foo(), and you want all of its callers to call bar() instead. You can rename the foo method to bar, then remove the method.

Extract

As you develop or maintain your code, you’ll often find pieces of code that should be defined elsewhere. This is really easy to do with extraction—you can extract variables and statements into methods, variables, fields, constants, or parameters.

As a trivial example, suppose you just wrote the following method:

int addThenSquare(int x, int y) {
    int sum = x + y;
    return sum * sum;
}

You want to clean this up a bit by factoring out the squaring part. Just place your cursor on either sum (or select the expression) and extract method. IntelliJ will leave you with something like this:

int addThenSquare(int x, int y) {
    int sum = x + y;
    return square(sum);
}

int square(int sum) {
    return sum * sum;
}

The hotkeys for these extractions all start out the same: ⌘⌥. They’re combined with the first letter of the extraction you want to use. For example, to extract a method, use ⌘⌥M.

Move (F6)

This one’s pretty straightfoward—it allows you to move a piece of code somewhere else.

Change Signature (⌘F6)

Oftentimes you’ll need to change your existing methods—adding parameters, removing parameters, changing return types, etc. The change signature dialog allows you to update both the signature and all of the method’s callers at once.

  1. Although IntelliJ is now the most popular dev environment at Yext, we do have a few developers using Eclipse, emacs, vim, or even Sublime Text.