Eclipse Tip: Custom Surround With

Previously I have posted the following tips:

Eclipse Tip: Surround With
Eclipse Tip: Remove Surrounding Statement

I thought that I will add to it a little bit. In Eclipse you can now add your own “Surround With” templates. Let us say we need to surround a piece of code with comments like:

Select the code and press Alt+Shift+Z and select “Configure Templates”.

Now create a template with the variable ${line_selection} in it. By using this variable the template shows up automatically in the Surround With templates and this is the location where the selected text will be in the end. Here is the template for the above example.

// ** Start Comment
// ${todo} ${cursor}
// ** End Comment

Vasanth Dharmaraj is a Java Architect currently working for Western Union living in the Bay Area. He is interested in programming, gadgets, formula one... You can follow him on Twitter.

Posted in Eclipse, Java

Ads By Google