Multiline Search and Replace in Eclipse

Posted on February 24, 2008

Thanks to the CFEclipse plug-in, more and more ColdFusion developers have been moving to Eclipse as their primary editor and IDE. The one complaint I’ve heard most often from people familiar with HomeSite, CF Studio and DreamWeaver is that there’s no way to search for blocks of code. Thanks to Aptana, that is no longer a problem.

Search and Replace with Eclipse

As with most editors, Ctrl+F brings up the in-page Search dialog. Eclipse, however, has a bit more functionality available for even the most basic things.

In order to search across multiple files, use Ctrl+H to bring up an extended Search dialog.

In both dialogs, your search can be Case Sensitive or use Regular Expressions. The extended search lets you search across certain file types, so if you only want to search through CFCs, enter “*.cfc”.

But the “where” involved with the default Extended Search can be a bit tricky. In the Scope section, we have a few options:

  1. Workspace - searches through all Projects in the current workspace.
  2. Selected Resource - select a folder from a Project or Working Set, then Ctrl+H and mark this option to restrict the search to that folder.
  3. Enclosing Project - CF users won’t use this much. IIRC, in setting up Java Projects, one project can be built within others, so this would search higher level projects. This is not the same as Related Projects
  4. Working Set - here you can choose one or more defined Working Sets to search.

Once you’ve defined your parameters, you can opt to Search only or to Search and Replace across multiple files.

Now, for some reason, the Eclipse developers decided that all searches should be restricted to a single line of text. You can add newline characters and Regular Expressions, I suppose, but for the average (read: non-complete-and-utter-geek) user, this is just a deterrent to using this fine IDE.

Search and Replace with Aptana

Aptana Studio is a Web Development IDE built on top of Eclipse. It takes care or HTML, JS, CSS, PHP, AIR and all kinds of other programming language editing.

Big deal, where’s my code block search?

Once you’ve installed Aptana, Ctrl+H brings up a new tab in the Search Dialog.

First, let’s take a look at the new options in Scope. In addition to the original four, we now have

  1. Directory - with the standard Eclipse Search, you can only search within folders that are in defined Projects in the Workspace. This option lets you search any folder on your system.
  2. Open text editors - restricts the search to whichever text files you have open in any editor.

Finally, da da daaaaa!, click on the “Text is multiline” option under the “Containing text” field and you can enter blocks on text including spaces, tabs and what all else.

Notice that part of the Scope area disappears when you select this option, just resize the dialog and you can access everything again.

Of course, in addition to multiline search and replace, Aptana provides a ton of editors to compliment CFEclipse. You’ll forget it’s even there when you open non-CF files. If you’re a diehard HomeSite, ColdFusion Studio or DreamWeaver user, give them both a shot, they’re free.

Make sure to let them know how long it takes before Eclipse with CFEclipse and Aptana become your main development environment. :)

About the Author
Adrian J. Moreno

Adrian is a CTO and solution architect specializing in software modernization. More information