Eclipse 用引号和其他块包围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5622609/
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
Eclipse surround with quotes and other blocks
提问by dstarh
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.
我发现自己想在 eclipse 中突出显示一个字符串并用双引号或单引号引用它。我似乎找不到它的捷径。例如,在 textmate 中,如果我突出显示一个字符串并键入一个 ' 或一个 " 字符串将被它们包围。同样应该适用于 ) 和 } 我认为也是如此。
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.
我已经添加了一个代码模板来做这件事,但它从来没有出现在菜单中,而且似乎也没有办法为它创建快捷方式。请注意,这应该完全由键盘驱动,不涉及任何二级菜单,无论如何这就是我的目标。
回答by janhink
Go to Java > Editor > Templatesand add a new template, e. g. called quote
, as follows:
转到Java > Editor > Templates并添加一个新模板,例如 called quote
,如下所示:
"${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.
然后,在编辑器中,写下您要引用的文本,选择它,按Ctrl+Space,键入quote
并点击Return。现在应该引用突出显示的文本。
If you don't get template proposals when pressing Ctrl+Space, make sure you have them checked in Java > Editor > Content Assist > Advanced.
如果按Ctrl+时没有收到模板建议Space,请确保在Java > Editor > Content Assist > Advanced 中检查了它们。
Just tried it and it works for me!
刚试过,它对我有用!