Eclipse 键盘命令添加导入语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4763945/
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 keyboard command to add import statement
提问by ahsteele
I am a C# developer who is doing some Android development in Eclipse. One of my favorite keyboard shortcuts in Visual Studio is CTRL+ .which brings up the SmartTag menu. This is incredibly useful for adding using statements on the fly.
我是一名 C# 开发人员,正在 Eclipse 中进行一些 Android 开发。我在 Visual Studio 中最喜欢的键盘快捷键之一是CTRL+ .,它会调出 SmartTag 菜单。这对于动态添加 using 语句非常有用。
As an example if I don't have an import statement for System.Xml.Linq
but create a variable of type XDocument
I can quickly add the appropriate using with the keyboard command.
例如,如果我没有导入语句System.Xml.Linq
但创建了一个类型的变量,XDocument
我可以使用键盘命令快速添加适当的 using。
Is there a similar keyboard command available in Eclipse?
Eclipse 中是否有类似的键盘命令可用?
回答by Crembo
I'm pretty sure he has Ctrl+ Shift+ Oin mind, but I may be wrong.
我敢肯定他有Ctrl+ Shift+O的心意,但我可能是错的。
回答by Chris Roberts
You can use Ctrl+ Shift+ Oto "O"rganize Imports (like Crembo mentions). Another neat trick is to go to Windows > Preferences, search for "Save Actions", and check "Organize Imports". Now whenever you save (Ctrl+ S), Eclipse will automatically run the "organize imports" feature. I find this quicker, since it's quicker for me to hit Ctrl+ Sthan Ctrl+ Shift+ O(one-hand shortcut versus two-hand shortcut).
您可以使用Ctrl+ Shift+ O,以“O” rganize进口(如Crembo提到)。另一个巧妙的技巧是转到 Windows > Preferences,搜索“Save Actions”,然后选中“Organize Imports”。现在,无论何时保存 ( Ctrl+ S),Eclipse 都会自动运行“组织导入”功能。我发现这更快,因为我点击Ctrl+S比Ctrl+ Shift+更快O(单手捷径与双手捷径)。
回答by Mehlyfication
For Mac users the shortcut is:
对于 Mac 用户,快捷方式是:
CMD+ Shift+ O
CMD+ Shift+O
回答by shiluka
some useful Eclipse shortcuts, you need first one
一些有用的 Eclipse 快捷方式,你需要第一个
1. Ctrl+ Shift+ O: Organize imports
1. Ctrl+ Shift+ O: 组织进口
Ctrl+ D: Delete row
Ctrl+ 1: Activate quick fix
Ctrl+ O: Open declarations
Ctrl+ /: Line Comment
Alt+ Shift+ R: Rename selected element
Ctrl+ Shift+ L: Shortcut for shortcuts
Ctrl+ D: 删除行
Ctrl+ 1: 激活快速修复
Ctrl+ O: 打开声明
Ctrl+ /: 行注释
Alt+ Shift+ R: 重命名所选元素
Ctrl+ Shift+ L: 快捷方式的快捷方式
if you need more refer here
如果你需要更多参考这里
回答by Konstantin Komissarchik
The easiest thing to do is to start typing the type name, then press Ctrl+ Spaceto get the completions. Selecting the completion will complete the type name that you are typing and will also add the import statement. Short of that, there is Ctrl+ 1, which will bring up quick fixes when you are over a piece of code with problem. There is typically a quick fix to import type.
最简单的方法是开始输入类型名称,然后按Ctrl+Space以获取补全。选择完成将完成您正在键入的类型名称,并且还将添加导入语句。除此之外,还有Ctrl+ 1,当您解决一段有问题的代码时,它会提供快速修复。通常可以快速修复导入类型。
回答by Rachel
In Preferences->General->Key, you can have your bindings for shortcut key. This article: Eclipse Short Cut Keyslists some useful shortcuts.
在 Preferences->General->Key 中,您可以绑定快捷键。这篇文章:Eclipse Short Cut Keys列出了一些有用的快捷键。