Eclipse Tips
David Matuszek
Keyboard shortcuts
Some people like to learn all the keystroke "shortcuts," so they never
have to take their hands from the keyboard. I'm not one of them. Research has
consistently shown:
- People perceive keyboard shortcuts as being faster than
using the mouse.
- Using the mouse is actually faster than keyboard shortcuts.
Nevertheless, there are some keystroke "shortcuts" that I think
you should learn. Not only are they very useful, but some of them are
buried in sub-menus that are not easy to find, so the keystrokes probably
really are faster. Here they are, most important ones first:
F3
- Click on any variable name, class name, or method name, and press Function 3.
This will bring you immediately to the place that that name is declared or
defined, even if it is in a different
.java file.
Ctrl-K
- Select anything in the editor and this keystroke will bring you to the next
occurrence of that thing. Repeat as often as you like. You can set this
search to wrap.
Alt-Shift-J
- Generate a "skeleton" Javadoc comment. The mouse must be in the
method definition or on the class name for this to work.
Ctrl-/
- Add (or remove)
// at the beginning of each line in the selection.
Ctrl-I
- Correctly indents the selected lines. This command just indents--it doesn't
correct bad spacing, or move anything from one line to another.
Ctrl-Shift-F
- Reformats the selected lines, correcting indentation and spacing, and moving
things from one line to another as necessary. Formatting is done according to
your preferences; you should use the default for Java programs by going to
Project → Properties → Java Code Style → Formatter, clicking
Configure workspace settings... (so it applies to all your projects,
and choosing Java Conventions [built-in].
Choosing an editor font
Go to Window → Preferences... → General → Appearance
→ Colors
and Fonts → Java → Java Editor Text Font and click Change....
Here's what you want in a font:
- It should be easily readable in small sizes (so you can get a lot
on the screen),
- It should be very easy to distinguish certain easily
confused characters: 0 and O (zero and capital o); I and 1 and l and
| (capital i, one, lowercase L, and vertical bar); : and ; (colon and
semicolon); , and . (comma and period); ( and { and [ and ) and } and
] (parentheses, braces, and brackets). It isn't enough to be able to
distinguish them--they have to be different enough so that you notice when
you have the wrong one.
- For programming, a monospace font (in which all the letters are the same
width) is generally preferred.
Courier or Courier New is generally OK. In Moore 207, I like bitstream
vera sans mono at
10 point.
Typing support
Go to Window → Preferences... → Java → Editor → Typing and
check everything. Then try some editing and see if you like the
way it behaves. Give it a chance--don't reject it immediately just because
it's different.
Hint: Some things, like putting semicolons at the end of a line, can be undone
by hitting the backspace key.
Automatic file saves
When I run a program, I don't like always having to say yes, save the files
first. To avoid this dialog box, go to Window → Preferences... → Run/Debug
→ Launching and under Save required dirty editors before launching,
choose Always. Under General Options, check Build (if
required) before launching.