A few days ago I was working with eclipse (or more precisely with Aptana 1.5) on a project. I have accidentally closed a file, although I was not finished yet. In trying to open this file again I could have go to the „Project View“ open it through the directory list.
We know this shortcut from many other programs to open a recently closed window/tab. So why shouldn’t it work in eclipse? So I just tried to reopen the file useing the shortcut:
CTRL + SHIFT + T
Unfortunately, this shortcut does not open the last closed file, but it has opened a window titled „Open PHP Element“, which looks like this:
This is a search window where you can search for classes, functions and constants. By default it always searches in all projects. As you can see in my example search, you can also search for methods of a class. But it is important to know, that the search always start at the beginning of an identifier. However, preceding the search term with an asterisk you can search within the identifier for a search term:
Das ist auch dann notwendig, wenn man z.B. den Methodennamen einer Klasse kennt, nicht aber den Namen der Klasse, in der die Methode enthalten ist.
It is also necessary if you only know the method name of a class, but not the name of the class, in which the method is included.
Double-clicking on an entry of the search result opens the file in which the class, function or constant is defined, and jumps to the appropriate location. This is especially useful if the corresponding functions are not described with the help of PHPDoc and you want to find out exactly what the function does. Especially when working with WordPress, it is often very helpful to look up whether there is a filter in a function, when this filter is running and what it does.
In my current installation of Eclipse with the Aptana plugin, the shortcut can only be used if I’ve just opened a file that is associated with one of the Aptana editors. So if I just work in a text file or an SQL file, which is associated with a native eclipse editor, the shortcut does not work.
The indexing of the files for this search runs in the background. It is mostly performed after an update from a SVN respository. I was often wondered about what exactly Aptana does after an update for such a long time, but now I know.
Related shortcuts und alternative plugins
There is also a function called „Open Ressource“. With this shortcut you can open a file by it’s name (and you can also use an asterix in the search term):
CTRL + SHIFT + R
But to search for files, I use the plugin GotoFile which can even handle small typos within the search term. You can either access the plugin directly (blank) or you can mark a word before opening the plugin, which makes finding files even faster (e.g. you are searching for a file that in included with the include() orrequire() function). The shortcut to open the plugin is the following:
CTRL + ALT + N
The plugin hasn’t been maintained since 2006, but it also works with the latest version of eclipse (3.6.1) and without problems. It can’t be added through the „Software Updates …“. Instead you can simply unzip the zip archive into the plugins folder of your Eclipse installation.
I’m very excited from the newly discovered function. Because many times I know exactly how a function is called, but not necessarily where it was implemented. But even if you know where it is implemented, you can jump so much quicker to the appropriate place. It has saved me quite a lot of time searching.
I hope that the shortcut (or the plugin) may also help you in your daily work. If any of you has a great suggestion for a shortcut I would be very happy about a comment. I will post it on my blog ot you can write the post and I publish it for you.