dstarh dstarh - 3 years ago 187
Java Question

Eclipse surround with quotes and other blocks

I find myself wanting to highlight a string in eclipse and double or single quoting it. I can't seem to find a shortcut for it. In textmate for example if i highlight a string and type either a ' or a " the string will be surrounded with them. The same should work with ) and } i think as well.

I've added a code template for doing it but it doesn't ever appear in the menu and there doesn't seem to be a way to create shortcuts for it either. Note that this should be entirely keyboard driven and not involve any secondary menus, that's my goal anyway.

Answer Source

Go to Java > Editor > Templates and add a new template, e. g. called quote, as follows:

 "${word_selection}"${cursor}

Then, in the editor, write a text you want to quote, select it, press Ctrl+Space, type quote and hit Return. The highlighted text should be quoted now.

If you don't get template proposals when pressing Ctrl+Space, make sure you have them checked in Java > Editor > Content Assist > Advanced.

Just tried it and it works for me!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download