These are the ones I use more often and that immediately come to my mind right now. I have ignored the usual CTRL+C, CTRL+V ones 😉
- CTRL + Space
- code sense: a little dropdown will show up, with available functions/variables depending on what you have already written
- Alt + /
- They call it autocomplete, I would call it suggest. It’s not exactly the same than code sense. Try it out.
- CTRL + F
- Search in the currently edited file
- CTRL + H
- Global search (in the project, workspace, etc)
- CTRL + D
- Delete the current line
Searching and replacing
To my surprise, most Eclipse users I have spoken to don’t use the more advanced options from the Find/Replace dialog, when it can save you some precious time.
- I always enable the Wrap search check box, so that I don’t have to worry whether I’m above or after the word I’m looking for.
- The Incremental check box might be useful sometimes. If you enable it, when you begin typing in the text you’re looking for, it will begin searching at the same time (it won’t wait for you to press the Find button). It’s similar to Firefox’s Search as you type feature.
But the crown jewel is the Regular expressions check box. Regexp’s can save you literally hours of agonising and boring manual replacements. I’ll demonstrate you why with a simple example:
Imagine we have a php file where we’re accessing the members of an associative array. Something along the lines of this:
$user['name'] = $user['first_name'] . ' ' . $user['last_name'];
Then one day you need to replace those associative arrays with objects. The above code will no longer be valid and you’ll need to update it manually.
It won’t matter too much if you’re just updating a few lines, but imagine the code was longer and you had to perform the same action in several places. Suddenly having to replace $user[‘name’] with $user->name everywhere, manually, doesn’t seem that simple or easy…
But if you enable the Regular expressions check box and enter this in the Find field:
and this in the Replace With field…
… and then press Replace All, your code is quickly updated to the new working version:
$user->name = $user->first_name . ' ' . $user->last_name;
Isn’t that super great? And that’s just a small example, but I hope it serves to show you how awesome that forgotten and ignored feature is.
Something great too is that neither regular expressions nor support for them are new or unique to Eclipse. Once you learn how to use them, you can use those abilities in lots of places. If you’re interested in regular expressions, there are literally TONS of tutorials and resources about them, but here‘s a good starting point. However, the best way to learn is to practise as much as you can, and then a little bit more 🙂
The tasks list
Leave short comments in the code like the following ones:
// TODO change to use config settings
// FIXME this never returns a value
// XXX refactor
… and Eclipse will show them all in a nice tasks list, which you can access in the bottom area of the IDE, clicking on the Tasks tab.
You can also check them off as you complete them. In that case they would show up after the non-completed ones, but I personally prefer to delete them from the source code when they are done. It’s up to you 🙂
So that’s for now. Hope you enjoyed the tricks, and they help you make more with less 😉 If you have any other trick that I overlooked, please post it in the comments, I would love to hear about it!