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}
${line_selection}
// ** End Comment