1. 没必要再去用鼠标框选某段代码了。idea可以将你光标所在地方的代码,逐步向外框选,只要你不停地CTRL+Wjava
Ctrl+W (extend selection) in the editor selects the word at the caret and then selects expanding areas of the source code. For example, it may select a method name, then the expression that calls this method, then the whole statement, then the containing block, etc. You can also select the word at the caret and the expanding areas of the source code by double-clicking the target areas in the editor.express
2. 把 一些表达式和语句重构成被某个变量应用的形式,能够如此自动化。只要选中表达式以后,点击Ctrl+Alt+V,重构、提取、建立变量引用的三个步骤一鼓作气了!windows
The Extract Variable refactoring helps you simplify complicated statements in your code. For example, in the code fragment below, you can select an expression in the code:数组
and press Ctrl+Alt+V (Refactor | Extract | Variable...). This will result in the following:app
3.若是如今有两个数组,我想写个循环遍历一下。这个场景是否是常常出现?idea不知道是否是想得太多,仍是想得太周到了,竟然有这样的功能:在有了数组的定义以后,只要另起一行代码输入itar以后,再按Tab,for循环就自动生成了。并且若是有多个数组,如今自动生成的那个不是你要的,能够经过继续按Tab键进行自动切换,直到正确为止。ide
注意:List类型是不支持的。函数
Try Live Templates
Live Templates allow you to generate many typical code constructs in seconds! For example, type优化
in a method and press the Tab key to see what happens.ui
Use the Tab key to move between the template fields. See File | Settings | Live Templates for more details.this
4. Idea根据类型名称自动为你的变量引用起名字。
但是,这个功能的快捷键着实有点蛋疼,Ctrl+空格与windows输入法切换快捷键冲突,建议本身在idea中从新设置吧。
The CodeCompletion feature can suggest a name for a variable when you declare it. For example, start typing
private FileOutputStream
and press Ctrl+空格.
You can customize name prefixes for local variables, parameters, instance and static fields in File | Settings | Code Style.
5. 当你须要将某个对象的调用的方法替换为它的其余参数列表的重载函数时,能够将光标移到函数调用以前,而后按Ctrl+P。
If the cursor is between the parentheses of a method call, pressing Ctrl+P brings up a list of valid parameters.
public class TestController { public void fn(){ Apple.getInstance().bibi(); } } class Apple{ private static Apple instance; private Apple(){ } public static Apple getInstance(){ if(instance==null) { instance = new Apple(); } return instance; } public void bibi(){ } public void bibi(int a){ } public void bibi(String a){ } }
效果以下:
又或者
6. 如何迅速找到刚才修改代码的位置呢?按Ctrl+Shift+Backspace,光标会迅速移动到刚才修改的位置。注意:这个返回上次修改的地方不是指当前文件上次修改的地方,而是整个编辑project上次编辑的地方。所以,Ctrl+Shift+Backspace会让当前的光标先回到上次编辑发生的那个文件,而后定位到最后修改的地方。
还有就是,若是屡次按Ctrl+Shift+Backspace,会按照依次访问你刚才访问倒数第n次的地方移动光标。
Ctrl+Shift+Backspace (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.
7. 遍历某一个变量出现的位置。
当你把光标点击在某个变量,可前可后,而后点击Ctrl+Shift+F7,idea会自动将代码中全部出现这个标量的地方高亮。而后你能够用F3 和 Shift+F3 分别先后遍历它们。
可是,若是你一开始是把光标选中那个变量名后者某段代码字符串,点击Ctrl+Shift+F7,idea会将全部包含该字符串的地方高亮。
Use Ctrl+Shift+F7 (Edit | Find | Highlight Usages in File) to quickly highlight usages of some variable in the current file.
Use F3 and Shift+F3 keys to navigate through highlighted usages.
Press Esc to remove highlighting.
8. 在Code | Reformat 下能够对自动调整代码格式Ctrl+Alt+L 有定制化的设置。
代码的更加详尽的定制,能够在File | Settings | Code Style 目录下设置。
经过目录Code | Optimize Imports, 或者快捷键Ctrl+Alt+O 能够优化源文件的import语句,去除没有使用的等。详细的定制方法能够经过目录 File | Settings | Code Style | Imports 进行定制。
Use Code | Reformat Code to reformat code according to your code style preferences (File | Settings | Code Style).
You can also use Code | Optimize Imports to automatically optimize imports (remove unused imports, etc.). To access the corresponding settings, use File | Settings | Code Style | Imports.
9. 当你在查看某个很是长的方法的时候,若是想看看这个方法的签名(返回类型、方法名、参数列表),要不停的滑动滚轮。idea提供了一个方便的方法,当光标处于某个方法体内时,按Alt + Q,可以快速 这个方法的签名。
再按一下 Alt + Q,能看到所处类的声明,包括注解等。
Press Alt+Q (View | Context Info) to see the declaration of the current method without the need to scroll to it.
10. 查看最近访问过得的文件,按Ctrl+E,出现列表。多按几回,则列表中条目切换,回车打开相应的文件。
Ctrl+E (View | Recent Files) brings a popup list of the recently visited files. Choose the desired file and press Enter to open it.
Besides recent files, you can bring up results of the usage searches you have performed recently. To do that, use the same Ctrl+E shortcut with the Find tool window having the focus, and select the desired find usages result from the Recent Find Usages popup.