Friday, November 10, 2006

10 IDE Shortcuts Everyone Should Know

Below are 10 IDE shortcuts that everyone should know but many don't. These are tricks that save me lots of time. I use them so often they are hard-wired into my brain. They work in IntelliJ and Eclipse and probably others.

1. Introduce Variable

IntelliJ calls it "Introduce Variable" (Ctrl Alt V)
Eclipse calls it "Extract Local Variable" (Alt Shift L)

Here is how it works. You type this:

new FooBanger();

Then, with your cursor positioned at the end of the line, press Ctrl Alt V. IntelliJ prompts for a variable name and then changes the code to this:

FooBanger fooBanger = new FooBanger();

Alternately, if you have a long expression like this:


You can highlight an expression within the expression, for example:

Then press Ctrl Alt V. IntelliJ prompts for a variable name and changes your code to this:

Company c = x.getPerson().getCompany()

2. Goto File

IntelliJ calls it "Goto File or Goto Class" (Ctrl Shift N or Ctrl N)
Eclipse calls it "Open Resource" (Alt Shift L)

A large part of what modern IDE's do falls under the heading of "Project Navigation", i.e. making it easy to quickly move from file to file within a large project. This and the next two tips deal with project navigation.

If you remember the name of a file but don't feel like navigating 8 folders deep to get to it, then use this trick. Press Ctrl N. Then type the first few letters of a file name. The IDE then takes you to that file. You don't have to remember what folder the file is in.

3. Hyperlink (Jump to File)

This works the same in IntelliJ and Eclipse. Hold down the control key, then hover your mouse over a class name. As your mouse moves over the class name, it turns into a hyperlink. Click the hyperlink to goto the highlighted file.

4. The Back Button

IntelliJ and Eclipse both have a browser style Back button which takes you to the previous file you were working on.

5. Delete Current Line

Eclipse: Ctrl D (D for delete)
IntelliJ: Ctrl Y (Y for yank)

6. Duplicate Current Line

Eclipse: Ctrl Alt Down
IntelliJ: Ctrl D (D for duplicate)

OK, so I stopped at 6. This blogging business is tiring.

1 comment:

Anonymous said...

What are your thoughts on Ajax? Do you offer any classes on the topic?