Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a template (sleep) in Eclipse 4.2.1 that should expand to

try { Thread.sleep(1000); } catch (Exception e) {}

I want Eclipse to add it as one line, just as I put it in the template. However, Eclipse autoformats it after inserting to:

try {
    Thread.sleep(1000);
} catch (Exception e) {
}

I have tried @formatter:off, but that does not work. I have code cleanup switched off.

Is there any way to disable formatting for all templates, since the only templates I use are one-liners anyway?

share|improve this question

1 Answer 1

Window > Preferences > Java > Editor > Templates, as you know.

There is the list of templates, defaults given by Eclipse, and yours.

At the bottom of the dialog, in Eclipse Juno (4.2), I see a checkbox Use code formatter. Unchecking it deactivates the auto-format at insertion time.

Alas, it is a global setting, applied to all template... But well, that's what you look for, anyway.

[EDIT] I see the same checkbox in Indigo (3.7).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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