开发者

Eclipse keyboard command to add import statement

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 开发者_StackOverflowadding using statements on the fly.

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.

Is there a similar keyboard command available in Eclipse?


I'm pretty sure he has Ctrl + Shift + O in mind, but I may be wrong.


You can use Ctrl + Shift + O to "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 + S than Ctrl + Shift + O (one-hand shortcut versus two-hand shortcut).


For Mac users the shortcut is:

CMD + Shift + O


some useful Eclipse shortcuts, you need first one

1. Ctrl + Shift + O : Organize imports

  1. Ctrl + D : Delete row

  2. Ctrl + 1 : Activate quick fix

  3. Ctrl + O : Open declarations

  4. Ctrl + / : Line Comment

  5. Alt + Shift + R : Rename selected element

  6. Ctrl + Shift + L : Shortcut for shortcuts

if you need more refer here


The easiest thing to do is to start typing the type name, then press Ctrl + Space to 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.


In Preferences->General->Key, you can have your bindings for shortcut key. This article: Eclipse Short Cut Keys lists some useful shortcuts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜