Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an Eclipse command to surround the current selection with parentheses?

Tags:

Is there an Eclipse command to surround the current selection with parentheses?

Creating a template is a decent workaround; it doesn't work with the "Surround With" functionality, because I want to parenthesize an expression, not an entire line, and that requires ${word_selection} rather than ${line_selection}.

Is there a way that I can bind a keyboard shortcut to this particular template? Ctrl-space Ctrl-space arrow arrow arrow isn't as slick as I'd hoped for.

like image 961
erickson Avatar asked Sep 15 '08 21:09

erickson


People also ask

What is Ctrl Shift G in Eclipse?

Search – Eclipse Shortcuts CTRL SHIFT G – Search for current cursor positioned word reference in workspace. CTRL H – Java search in workspace.

What does Ctrl Shift t do in Eclipse?

Switching between Open Editors Ctrl + Page Up and Ctrl + Page Down—Navigate to previous or next file from the list of open files. Ctrl + Shift + T—Display a list of classes from the workspace. Ctrl + Shift + R—Display a list of resources from the workspace.


2 Answers

Maybe not the correct answer, but at least a workaround:

  1. define a Java template with the name "parenthesis" (or "pa") with the following :

    (${word_selection})${cursor}

  2. once the word is selected, ctrl-space + p + use the arrow keys to select the template

I used this technique for boxing primary types in JDK 1.4.2 and it saves quite a lot of typing.

like image 69
Vladimir Avatar answered Sep 19 '22 14:09

Vladimir


Easy, Window->Prefs, then select Java->Editor->Templates

Create a new template with : (${line_selection}${cursor})

The "line_selection" means you have to select more than one line.

You can try creating another one with "word_selection", too.

Then, select text, right click, Surround With... and choose your new template.

like image 41
DustinB Avatar answered Sep 18 '22 14:09

DustinB