是否有 Eclipse 命令用括号将当前选择括起来?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/66986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an Eclipse command to surround the current selection with parentheses?
提问by erickson
Is there an Eclipse command to surround the current selection with parentheses?
是否有 Eclipse 命令用括号将当前选择括起来?
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}
.
创建模板是一个不错的解决方法;它不适用于“环绕”功能,因为我想将表达式而不是整行括起来,这需要${word_selection}
而不是${line_selection}
.
Is there a way that I can bind a keyboard shortcut to this particular template? Ctrl-spaceCtrl-spacearrow arrow arrow isn't as slick as I'd hoped for.
有没有办法将键盘快捷键绑定到这个特定模板?Ctrl- spaceCtrl-space箭头箭头箭头并不像我希望的那样圆滑。
回答by Vladimir
Maybe not the correct answer, but at least a workaround:
也许不是正确答案,但至少是一种解决方法:
define a Java template with the name "parenthesis" (or "pa") with the following :
(${word_selection})${cursor}
once the word is selected, ctrl-space+ p+ use the arrow keys to select the template
使用以下内容定义一个名为“括号”(或“pa”)的 Java 模板:
(${word_selection})${cursor}
选择单词后,ctrl- space+ p+ 使用箭头键选择模板
I used this technique for boxing primary types in JDK 1.4.2 and it saves quite a lot of typing.
我在 JDK 1.4.2 中使用这种技术对主要类型进行装箱,它节省了大量的输入。
回答by DustinB
Easy, Window->Prefs, then select Java->Editor->Templates
简单,Window->Prefs,然后选择Java->Editor->Templates
Create a new template with : (${line_selection}${cursor})
创建一个新模板:(${line_selection}${cursor})
The "line_selection" means you have to select more than one line.
“line_selection”意味着您必须选择多于一行。
You can try creating another one with "word_selection", too.
您也可以尝试使用“word_selection”创建另一个。
Then, select text, right click, Surround With... and choose your new template.
然后,选择文本,右键单击,环绕...并选择您的新模板。