In Eclipse, create reusable editor templates from Window > Preferences > Java > Editor > Templates (on macOS, open Eclipse > Settings or Preferences, then follow the same Java path). Choose a context, write a pattern with variables, and invoke it in the Java editor through content assist with Ctrl+Space. Templates can insert linked placeholders, but they do not check whether the expanded code suits your project.
What Eclipse editor templates do
The Eclipse Foundation describes templates as “a structured description of coding patterns that reoccur in source code.” A template is a named pattern you can insert while editing, rather than retyping a recurring fragment. For example, a simple print template could use this pattern:
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Eclipse IDE Pocket Guide: Using the Full-Featured IDE | $9.71 | Buy on Amazon |
| 2 |
|
Competitive Programming 4 - Book 1: The Lower Bound of Programming Contests in the 2020s | $20.79 | Buy on Amazon |
| 3 |
|
Eclipse | $25.96 | Buy on Amazon |
| 4 |
|
Eclipse Cookbook: Task-Oriented Solutions to Over 175 Common Problems | $22.27 | Buy on Amazon |
| 5 |
|
The C Programming Language | $42.74 | Buy on Amazon |
System.out.println(${text});
When you insert it, Eclipse presents ${text} as an editable placeholder. Repeating the same variable name in a pattern links those occurrences, so changing one updates the others. Variables can also derive values from the current editor context, suggest names, add imports, or place the caret with ${cursor}.
These are editor templates, offered as content-assist proposals. They are distinct from Java > Code Style > Code Templates, which configure text generated by actions and wizards, such as comments or method bodies.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Create a focused Java template
- Open the preference page. Go to Window > Preferences > Java > Editor > Templates. In the list, you can inspect built-in templates or create, edit, and remove entries.
- Start a new entry. Choose the control for creating a template. In the dialog, enter a short, memorable name, a description, and the pattern. The dialog also lets you choose a context and whether a matching template can be inserted automatically when it is the only proposal.
- Select the context. Choose where the template should be available: general Java code, a type member, a statement, or Javadoc. Java and Javadoc are separate contexts; the available contexts and variables depend on the choice. Some context options may depend on SWT being on the project build path.
- Build the pattern. Use the dialog’s Insert Variables aid to check which variables are available in that context. Put
${cursor}where editing should resume after the linked template-edit session. - Save and try it in code. In the appropriate editor location, type the template name or prefix and press Ctrl+Space. Choose the intended proposal. If automatic insertion is enabled and it is the only matching proposal, Eclipse can insert it without requiring a separate choice.
For a pattern with a repeated value, for example, log.info("${message}"); and System.out.println("${message}");, using the same variable name in both places links the two editable locations. Add a final ${cursor} if you want the caret to land at a specific point after filling them in.
Choose the right context and variables
A template context controls both where a proposal appears and which variables Eclipse can resolve. Use the narrowest context that fits the pattern: a declaration intended as a type member should not be offered in arbitrary statement positions, and documentation text belongs in the Javadoc context. This reduces irrelevant proposals and makes templates easier to discover.
| Context or variable type | What it is for |
|---|---|
| Java | Patterns used in Java source code; the dialog’s variable list shows what is available for the selected Java context. |
| Java type member | Patterns intended for members of a Java type. |
| Java statement | Patterns intended for statement positions. |
| Javadoc | Patterns inserted in Java documentation comments; it is separate from Java code context. |
| General variables | Values such as ${date}, ${year}, ${user}, ${file}, ${enclosing_type}, ${enclosing_method}, ${enclosing_package}, selection variables, and ${cursor}. |
| Java-specific variables | Variables can find visible variables of a requested kind, derive element or type information, suggest a non-conflicting local name with newName, add an import with :import, or offer choices with link. |
The exact variable set can vary with context and Eclipse version. Use Insert Variables in the template dialog as the authority for the current entry instead of assuming a variable works everywhere.
Design templates that remain useful
- Use a mnemonic name. A short prefix is easier to type and recognize among content-assist proposals.
- Automate only repeated work. Templates are most useful for recurring patterns, not one-off blocks that are faster to write directly.
- Keep the expansion readable. A template should reduce typing without hiding control flow or project-specific decisions.
- Review the result after insertion. Check imports, exception handling, framework APIs, and local conventions; template expansion does not validate code.
Export, import, and restore templates
To share a Java editor template collection, return to Java > Editor > Templates in Preferences and use Export to save templates or Import to load them. The page also provides options to restore removed predefined templates and revert predefined entries to their defaults; these reset actions do not change user-created templates.
Rank #3
Use older template examples carefully
Tomas Kramar’s DZone article “Effective Eclipse: Custom Templates”, published February 28, 2008, demonstrates the mechanics with examples including a Java logger, guarded logging, a BufferedReader loop, Maven XML, servlet configuration, JSP Spring form tags, and a Spring FreeMarker configuration. Its examples can still illustrate placeholders, linked values, and context-specific libraries, but they are historical examples rather than compatibility guidance. Before adopting a literal pattern, verify the logging API, Java resource and exception handling, XML schema, tags, and framework versions against your current project.
Quick Recap
Best Value
Rank #4
- Used Book in Good Condition
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

