注释代码(反注释代码):
- Ctrl+L
代码格式化:
- Win/Linux下: Ctrl + Alt + L
- Mac: Option + Command + L
导入相应的包申明 import :
- Alt+Enter (注意:在xml中是提取资源,如从布局文件中提取字符串到strings.xml文件中)
定位代码修改处:
(Navigate | Last Edit Location) brings you back to the last place where you made changes in the code.
Pressing Ctrl+Shift+Backspace a few times moves you deeper into your changes history.
- Ctrl+Shift+Backspace
查看最近常编辑的文件:
- Ctrl+E
跳转到语法错误:
Use F2/Shift+F2 keys to jump between highlighted syntax errors.
- F2/Shift+F2
Use Ctrl+Alt+向上箭头/Ctrl+Alt+向下箭头 shortcuts to jump between compiler error messages or search operation results.
To skip warnings right click on the validation side bar / marker bar and choose Go to high priority problems only.
从剪切板中粘贴最近剪切复制的内容:
- Ctrl+Shift+V
生成方法注释:
先输入 “/**” ,然后回车,就会自动加上 Parameters关键字。
获取帮助:
编辑快捷键
捷键 | 解释 |
---|---|
Ctrl + Space | Basic code completion (the name of any class,method or variable) |
Ctrl + Shift + Space | Smart code completion (filters the list of methods and variables by expected type) |
Ctrl + Shift + Enter | Complete statement |
Ctrl + P | Parameter info (within method call arguments) |
Ctrl + Q | Quick documentation lookup |
Shift + F1 | External Doc |
Ctrl + mouse over code | Brief Info |
Ctrl + F1 | Show descriptions of error or warning at caret |
Alt + Insert | Generate code… (Getters, Setters, Constructors, hashCode/equals, toString) |
Ctrl + O | Override methods |
Ctrl + I | Implement methods |
Ctrl + Alt + T | Surround with… (if..else, try..catch, for, synchronized, etc.) |
Ctrl + / | comment注释/反注释一行代码comment |
Ctrl + Shift + / | 注释/反注释代码段comment |
Ctrl + W | Select successively increasing code blocks |
Ctrl + Shift + W | Decrease current selection to previous state |
Alt + Q | Context info |
Alt + Enter | Show intention actions and quick-fixes |
Ctrl + Alt + L | Reformat code格式化代码 |
Ctrl + Alt + O | Optimize imports导入 |
Ctrl + Alt + I | Auto-indent line(s) |
Tab / Shift + Tab | Indent/unindent selected lines |
Ctrl + X or Shift + Delete | Cut current line or selected block to clipboard |
Ctrl + C or Ctrl + Insert | Copy current line or selected block to clipboard |
Ctrl + V or Shift + Insert | Paste from clipboard |
Ctrl + Shift + V | Paste from recent buffers… |
Ctrl + D | Duplicate current line or selected block |
Ctrl + Y | Delete line at caret |
Ctrl + Shift + J | Smart line join |
Ctrl + Enter | Smart line split |
Shift + Enter | Start new line |
Ctrl + Shift + U | Toggle case for word at caret or selected block |
Ctrl + Shift + ] / [ | Select till code block end/start |
Ctrl + Delete | Delete to word end |
Ctrl + Backspace | Delete to word start |
Ctrl + NumPad+/- | 折叠/展开代码块Expand/collapse code block |
Ctrl + Shift + NumPad+ | 展开所有代码块Expand all |
Ctrl + Shift + NumPad- | 折叠所有代码块Collapse all |
Ctrl + F4 | Close active editor tab |
Ctrl + Shift + C | Copy Path |
Ctrl+ Alt + Shift + C | Copy Reference |
Ctrl + Period(句号) | 将指针放入方法体中,代码折叠或展开 |
打开粘贴复制面板:
search and replace
快捷键 | 解释 |
---|---|
Double Shift | Search everywhere |
Ctrl + F | 查找Find |
F3 | Find next |
Shift + F3 | Find previous |
Ctrl + R | 替换Replace |
Ctrl + Shift + F | 查找Find in path |
Ctrl + Shift + R | Replace in path |
Ctrl + Shift + S | Search structurally (Ultimate Edition only) |
Ctrl + Shift + M | Replace structurally (Ultimate Edition only) |
Usage search
快捷键 | 解释 |
---|---|
Alt + F7 / Ctrl + F7 | Find usages / Find usages in file |
Ctrl + Shift + F7 | Highlight usages in file |
Ctrl + Alt + F7 | Show usages |
Compile and Run
快捷键 | 解释 |
---|---|
Ctrl + F9 | Make project (compile modifed and dependent) |
Ctrl + Shift + F9 | Compile selected file, package or module |
Alt + Shift + F10 | Select configuration and run |
Alt + Shift + F9 | Select configuration and debug |
Shift + F10 | Run |
Shift + F9 | Debug |
Ctrl + Shift + F10 | Run context configuration from editor |
Debugging
快捷键 | 解释 |
---|---|
F8 | Step over |
F7 | Step into |
Shift + F7 | Smart step into |
Shift + F8 | Step out |
Alt + F9 | Run to cursor |
Alt + F8 | Evaluate expression |
F9 | Resume program |
Ctrl + F8 | Toggle breakpoint |
Ctrl + Shift + F8 | View breakpoints |
Navigation
快捷键 | 解释 |
---|---|
Ctrl + N | 跳转到制定的类中,包括内部类 |
Ctrl + Shift + N | Go to file |
Ctrl + Alt + Shift + N | Go to symbol |
Alt + Right/Left | Go to next/previous editor tab |
F12 | Go back to previous tool window |
Esc | Go to editor (from tool window) |
Shift + Esc | Hide active or last active window |
Ctrl + Shift + F4 | Close active run/messages/find/… tab |
Ctrl + G | 跳转到指定行 |
Ctrl + E | 打开最近编辑的文件界面 |
Ctrl + Alt + Left/Right | Navigate back/forward |
Ctrl + Shift + Backspace | Navigate to last edit location |
Alt + F1 | Select current file or symbol in any view |
Ctrl + B or Ctrl + Click | 跳转到变量、方法、类的声明的地方 |
Ctrl + Alt + B | Go to implementation(s) |
Ctrl + Shift + I | Open quick definition lookup |
Ctrl + Shift + B | Go to type declaration |
Ctrl + U | Go to super-method/super-class |
Alt + Up/Down | Go to previous/next method |
Ctrl + ] / [ | Move to code block end/start |
Ctrl + F12 | File structure popup |
Ctrl + H | 类的层次Type hierarchy |
Ctrl + Shift + H | Method hierarchy |
Ctrl + Alt + H | Call hierarchy |
F2 / Shift + F2 | Next/previous highlighted error |
F4 / Ctrl + Enter | Edit source / View source |
Alt + Home | Show navigation bar |
Ctrl + F11 | Toggle bookmark with mnemonic |
Ctrl + #[0-9] | Go to numbered bookmark |
Shift + F11 | Show bookmarks |
move移动代码的快捷键:
实例:快速跳转到某个class文件的指定行
方法:先按Ctrl + Shift + N ,然后输入你要打开的类的名字(不一定要完整输完),直到匹配唯一,然后在后面加上 “ :行数”
Refactoring
快捷键 | 解释 |
---|---|
F5 | Copy |
F6 | Move |
Alt + Delete | Safe Delete |
Shift + F6 | Rename |
Ctrl + F6 | Change Signature |
Ctrl + Alt + N | Inline |
Ctrl + Alt + M | Extract Method |
Ctrl + Alt + V | Extract Variable |
Ctrl + Alt + F | Extract Field ,提取变量,以改变其初始化的位置 |
Ctrl + Alt + C | Extract Constant |
Ctrl + Alt + P | Extract Parameter |
Alt + Enter | 在xml中是提取资源,如从布局文件中提取字符串到strings.xml文件中 |
Refactoring Code
Change Signature
Type Migration
public String greetings(String greet){
return "Hello " + greet;
}
Move 移动文件
Copy 文件
Extract Variable
Extract Constant
private void addName(String name, Bundle bundle ){
bundle.putString("name_key", name);
}
public static final String NAME_KEY = "name_key";
Extract Field
private Date getDate(){
return new Date();
}
Extract Parameter
private void setDate(){
mDate = new Date();
}
private void setDate(Date date){
mDate = date;
}
Extract Method
Push Members Down and Pull Members Up
When we talk about pulling something up, we mean that we will take something in the current class (usually a method or a field) and send it to the parent class or interface.
If the parent is a class, the content will be moved. If the parent is an interface, it will declare the method as part of the interface, keep the method in your class and add the @override annotation.
When we talk about pushing members down, that is exactly the opposite operation, we are sending content from the parent class/interface in the child class.
Replace Inheritance with Delegation
public class Patio extends Sandbox {
}
public class Patio {
private final Sandbox mSandbox = new Sandbox();
public Sandbox getSandbox() {
return mSandbox;
}
}
Wrap Method Return Value
Replace Constructor with Factory Method
public Sandbox(String shovel, int children) {
mShovel = shovel;
mChildren = children;
}
public static Sandbox createSandbox(String shovel, int children) {
return new Sandbox(shovel, children);
}
Convert Anonymous to Inner
new Thread(new Runnable()).start();
new Thread(new Runnable() {
@Override
public void run() {
//do something
}
}).start();
VCS/Local History
快捷键 | 解释 |
---|---|
Ctrl + K | Commit project to VCS |
Ctrl + T | Update project from VCS |
Alt + Shift + C | View recent changes |
Alt + BackQuote (`) | ‘VCS’ quick popup |
Live Templates
快捷键 | 解释 |
---|---|
Ctrl + Alt + J | Surround with Live Template |
Ctrl + J | Insert Live Template |
iter | Iteration according to Java SDK 1.5 style |
inst | Check object type with instanceof and downcast it |
itco | Iterate elements of java.util.Collection |
itit | Iterate elements of java.util.Iterator |
itli | Iterate elements of java.util.List |
psf | public static final |
thr | throw new |
General
快捷键 | 解释 |
---|---|
Alt + #[0-9] | Open corresponding tool window |
Ctrl + S | Save all |
Ctrl + Alt + Y | Synchronize |
Ctrl + Shift + F12 | Toggle maximizing editor |
Alt + Shift + F | Add to Favorites |
Alt + Shift + I | Inspect current file with current profile |
Ctrl + BackQuote (`) | Quick switch current scheme |
Ctrl + Alt + S | Open Settings dialog |
Ctrl + Alt + Shift + S | Open Project Structure dialog |
Ctrl + Shift + A | Find Action |
Ctrl + Tab | Switch between tabs and tool window |
界面快捷键:
Using Code Generation
public String mName;
Code Generation 之 Constructors构造器
Code Generation 之 Getters/Setters
Code Generation 之 Override Methods
Code Generation 之 Delegate Methods
这么解释起来有点抽象,你可以创建一个属性,比如
public class Test {
private String testStr; //在这个变量名上点右键“generate delegate methods"
...
你会发现所有String类以及父类Object类的所有方法都列出来了,你可以生成其中某个或全部方法的代理方法,例如生成length()方法的代理方法如下:
public int length() {
return testStr.length();
}
你可以看到”代理方法“一般只是简单的对父类型的同名方法做了调用,一般你还需要添加一部分功能,但是eclipse已经把重复劳动的那一部分替你做了。
Inserting Live Templates
快速插入代码块:File——settings——Editor——Live Templates
Styling Your Code
Surrounding With