Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse surround with quotes and other blocks

Tags:

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.

like image 795
dstarh Avatar asked Apr 11 '11 14:04

dstarh


People also ask

How do you use double quotes in eclipse?

"Strings" - A pair of double quotes ("") will be inserted when a single quotation mark (") is entered. (Parentheses) and [Square] brackets - A pair of brackets will be inserted when the opening bracket is entered.


1 Answers

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!

like image 120
janhink Avatar answered Sep 18 '22 11:09

janhink