I'm looking for a software development tool that will allow me to rewrite small pieces of code.

For example, if I have the following code:

quux(foo(abc), bar(xyz))

and would like to rewrite it as:

var f = foo(a)
var b = bar(xyz)
quux(f, b)

The tool will allow me to write a small regular expression to match the parts of the first quux call and rewrite it as the second. I have to repeat this process many times in several files. I would like to select each occurrence and tell the tool to process it. The tool should also allow me to save the replacement patterns.

The tool does not have to have full "re-factoring" ability, nor does it have to understand the syntax or semantics of the code. It should just treat the code as text to be edited.

Ideally, the tool will be a plugin for IntelliJ, Eclipse, or Sublime Text 2. FOSS is best, but a small, reasonable price is also acceptable.

  • 1
    It may be tough for a tool rewrite the code properly if it is not aware of the specific syntax and semantics of the language being used. – Jason Down Feb 27 '14 at 14:27
  • We are going to need some more detail from you about your specific use case in order to make an informed recommendation rather than just listing possible software. Please take a look at What is required for a question to contain "enough information"? for tips on what we are looking for, then edit your question to incorporate some of these improvements. IDE's with various syntax and language helpers are a dime a dozen. Text editors with regex based processing are also common. You don't even mention what language you are working with. – Caleb Feb 27 '14 at 16:16

Eclipse and IntelliJ both have a built-in template feature that does what you want. You enter a small bit of text and then hit tab (or whatever the bind button is) and it expands into the longer text and then you just fill in the details.

For example in IntelliJ I can type fori and hit tab and it produces

for(int i = 0; i < ; i++) {


I can fill in the end condition and the body and move on. Since it's just text replacement, it doesn't matter what language you're working in. You could create one that replaces fs with the entire Gettysburg Address if you want.

You can see what's available and create your own by going to File > Settings > IDE Settings > Live Templates.

I did a test with your example and it looks like it doesn't like spaces and punctuation in the abbreviation so I tried the following:

Abbreviation: quux

var f = 
var b = 
quux(f, b);

It's a little different from what you had but you don't have to type as many characters this way.

I don't use this feature very often but I know others who do and they say that it saves them time and in the case of team efforts helps make sure everyone is doing things the same way.

  • That's not exactly what I need. The code already contains the quux(foo(abc), bar(xyz)) strings. I need to replace them with the other multi-line string that I showed. I tried using regex-replace operations but the replacement is too difficult to write with the standard replace dialogs. – Ralph Feb 27 '14 at 17:15
  • @Ralph What specifically was difficult about it? – crownjewel82 Feb 28 '14 at 14:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.