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

折月煮酒 提交于 2019-12-03 03:43:47

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/66986/is-there-an-eclipse-command-to-surround-the-current-selection-with-parentheses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!