Eclipse 中的代码导航

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5298435/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:59:11  来源:igfitidea点击:

Code navigation in Eclipse

javaeclipsecode-navigation

提问by Nishan

I find it difficult to navigate through code for a big project involving many classes, XML files, SQL files etc.

我发现很难浏览涉及许多类、XML 文件、SQL 文件等的大型项目的代码。

I know Shift-Ctrl-Rto open resources, but thats where my little knowledge ends. How can I easily navigate through a hell of Java and non-Java files in Eclipse with just keyboard. Most of you gurus already will have a list of favorite code navigation shortcuts/tips, I suppose.

我知道Shift- Ctrl-R打开资源,但这就是我的小知识结束的地方。如何仅使用键盘在 Eclipse 中轻松浏览大量 Java 和非 Java 文件。我想,你们中的大多数大师都已经有了一个最喜欢的代码导航快捷方式/技巧列表。

Please share.

请分享。

Thanks!

谢谢!

回答by adarshr

Try these shortcuts:

试试这些快捷方式:

Ctrl+ Shift+ Rfor opening any resources

Ctrl+ Shift+R打开任何资源

Ctrl+ Efor switching between open windows

Ctrl+E用于在打开的窗口之间切换

Ctrl+ Shift+ Tfor opening loaded classes

Ctrl+ Shift+T用于打开装载的类

Ctrl+ Tfor opening type hierarchy

Ctrl+T用于打开类型层次结构

Ctrl+ Ofor viewing all the methods in a class / interface. Pressing this again shows you all the superclass methods too.

Ctrl+O用于查看类/接口中的所有方法。再次按此按钮也会显示所有超类方法。

Ctrl+ F11to run a previously run class.

Ctrl+F11运行以前运行的类。

Alt+ Shift+ Kand then Jfor running a class as Java Application.

Alt+ Shift+ K,然后J运行一个类,Java应用程序。

Holding Ctrlwhen clicking on a method / class / interface opens it.

Ctrl单击方法/类/接口时按住将打开它。

Also check out the Java Browsing perspective.

另请查看 Java 浏览透视图。

回答by vaichidrewar

F3 : Go to the declaration / definition of method / variable

F3 : 转到方法/变量的声明/定义

Cmd + [ : Go back

Cmd + [ : 返回

Cmd + ] : Go Forward

Cmd + ] :前进

Cmd + 1 : Quick Fix

Cmd + 1:快速修复

Cmd + T : Shows Class Hierarchy

Cmd + T :显示类层次结构

Cmd + Shift + o : Fix Missing Imports

Cmd + Shift + o :修复丢失的导入

Cmd + / : Comment / Uncomment code

Cmd + / : 注释/取消注释代码

Cmd + Shift + / : Comment/ Uncomment with block comment

Cmd + Shift + / :注释/取消注释块注释

Cmd + L : Go to Line

Cmd + L :转到行

Cmd + Shift + F : Auto Formatting

Cmd + Shift + F :自动格式化

Cmd + D : Delete Line

Cmd + D : 删除行

Ctrl + Q : Go to To Last Edited Place

Ctrl + Q :转到上次编辑的位置

Cmd + Shift + G : Search the Workspace for references to the selected method or variable

Cmd + Shift + G :在工作区中搜索对所选方法或变量的引用

Cmd + Shift + R: Open any file quickly without browsing for it in the Package Explorer:

Cmd + Shift + R:无需在包资源管理器中浏览即可快速打开任何文件:

Cmd + Shift + T: Open a type (e.g.: a class, an interface) . Unlike the previous shortcut, this even works when you don't have the Java source file in your workspace

Cmd + Shift + T:打开一个类型(例如:一个类,一个接口)。与之前的快捷方式不同,当您的工作区中没有 Java 源文件时,这甚至有效

Cmd+Shift + P : Find Closing Brace.

Cmd+Shift + P :找到右大括号。

Fn + Option + Del : Delete next word

Fn + Option + Del : 删除下一个单词

Option + Del : Delete previous word

Option + Del : 删除上一个单词

Shift + Fn + Cmd + Del : Delete to the end of the line

Shift + Fn + Cmd + Del :删除到行尾

Shift + Cmd + Del: Delete to the start of the line

Shift + Cmd + Del:删除到行首

Shift + Cmd + L : List all Eclipse Keyboard Shortcuts

Shift + Cmd + L :列出所有 Eclipse 键盘快捷键

Cmd + K : Find Next

Cmd + K :查找下一个

Shift + Cmd + K : Find previous

Shift + Cmd + K :查找上一个

Cmd + Enter : Insert line above

Cmd + Enter :在上面插入一行

Shift + Cmd + Enter : Insert a line below

Shift + Cmd + Enter :在下面插入一行

Alt + Shift + R : Renames variables / methods / classes, renaming the class files if necessary. Also fixes all references

Alt + Shift + R :重命名变量/方法/类,必要时重命名类文件。还修复了所有引用

回答by jumping-Hyman

Alt+ Left Arraow -- Goes back (just like in a browser)

Alt+ Left Arraow -- 返回(就像在浏览器中一样)

Alt+ Right Arraow -- Goes forward

Alt+ Right Arraow -- 前进

Ctrl+ Q-- Goes to the last edited line of code

Ctrl+ Q-- 转到最后编辑的代码行

Also a usefeul tip when looking for classes is to press Ctrl+ Shift+ Tand partially type the name of the class/interface/enum that you look for. For instance, if you were to look for a class named StringParserHelper, you could type SPH, or StrPH, or String*Hel, or *ParH. Exercise with the combinations. This will help you allot.

在查找类时还有一个有用的提示是按 Ctrl+ Shift+T并部分键入您要查找的类/接口/枚举的名称。例如,如果要查找名为 StringParserHelper 的类,则可以键入 SPH、StrPH、String*Hel 或 *ParH。用组合练习。这将帮助您分配。

Ctrl+ .Goes to next problem (compilation error or warning) Ctrl+ ,Goes to previous problem (compilation error or warning)

Ctrl+.转到下一个问题(编译错误或警告) Ctrl+,转到上一个问题(编译错误或警告)

There are many useful shortcuts. You can look at them by pressing Ctrl+ Shift+ L. Press it twice and you will be edit the keyboard shortcuts.

有许多有用的快捷方式。您可以通过按Ctrl+ Shift+来查看它们L。按两次,您将编辑键盘快捷键。

回答by Tomas Narros

Navigating code with Eclipse, using the keyboard? Here are some shortcuts I use with high frecuency:

使用键盘在 Eclipse 中导航代码?以下是我高频使用的一些快捷方式:

  • F3: while on a class name, a method name, or a variable reference, it opens the selected element declaration.
  • F4: Opens the type hierarchy view for the selected element (a class, or method...)
  • Shift+Ctrl+T: search and open a Java Type (note that it won't search on JSPs, XML files, etc. only will search the classes declared)
  • Ctrl+F6: Opens a dropdown with the list of open files (so you can change from one to another).
  • Ctrl+F7: Dropdown with the available views. It allows you to switch from code editor to the Navigator view (so you can open other files)
  • F3: 在类名、方法名或变量引用上时,它会打开选​​定的元素声明。
  • F4:打开所选元素(类或方法...)的类型层次结构视图
  • Shift+ Ctrl+ T: 搜索并打开一个 Java 类型(注意它不会搜索 JSP、XML 文件等,只会搜索声明的类)
  • Ctrl+ F6:打开一个包含打开文件列表的下拉列表(这样您就可以从一个文件更改为另一个文件)。
  • Ctrl+ F7:带有可用视图的下拉列表。它允许您从代码编辑器切换到导航器视图(以便您可以打开其他文件)

There are lot more, but I use thess few continually

还有很多,但我不断地使用这些

回答by Abdullah Khan

To add up a few

加起来几个

CtrlShiftO- To organize imports

CtrlShiftO- 组织进口

Ctrl1- To get suggestions on a specific line

Ctrl1- 获取特定线路的建议