Intellj Idea 快捷键逐个详说

https://my.oschina.net/happyBKs/blog/689862

https://my.oschina.net/happyBKs/blog/702647


1. 不必再去用鼠标框选某段代码了。idea能够将你光标所在地方的代码,逐步向外框选,只要你不停地CTRL+W

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.

 

2. 把 一些表达式和语句重构成被某个变量应用的形式,可以如此自动化。只要选中表达式之后,点击Ctrl+Alt+V,重构、提取、创建变量引用的三个步骤一气呵成了!

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:

 

3.如果现在有两个数组,我想写个循环遍历一下。这个场景是不是经常出现?idea不知道是不是想得太多,还是想得太周到了,居然有这样的功能:在有了数组的定义之后,只要另起一行代码输入itar之后,再按Tab,for循环就自动生成了。而且如果有多个数组,现在自动生成的那个不是你要的,可以通过继续按Tab键进行自动切换,直到正确为止。

注意: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.

Use the Tab key to move between the template fields. See File | Settings | Live Templates for more details.

 

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.


11. 自动代码补全Ctrl+空格。与eclipse中的alt+/ ,VS中的 alt + 向右,类似。如果输入的开头对应的补全结果只有一个则直接自动补全类名、变量名等代码,对应补全的结果有多个,则出现列表选择。注意:Ctrl+空格与系统输入法切换冲突(win8以上搜狗输入法中英文切换,win7以下为windows自身的输入法切换快捷键),所以应把输入代码时的输入法先换为windows自身的英文输入法,或者还是更改idea的快捷键吧。

The Code Completion feature lets you quickly complete different kinds of statements in the code. For example, start typing a class name and press Ctrl+空格 to complete it. When multiple choices are available, they are shown in the lookup list.

 

12. get set 等自动生成。按快捷键:alt+insert

 

13.迅速查找某个东西在项目中的所有出处,这个东西可以是一个类、方法或者变量名称等。

只要你将光标点在上面,然后按Alt+F7。比如点中某个变量,按Alt+F7后,编辑区源代码所有引用该变量的地方高亮显示,idea下方弹出项目下查找结果列表。

You can quickly find all places where a particular class, method or variable is used in the whole project by positioning the caret at the symbol's name or at its usage in code and pressing Alt+F7 (Edit | Find | Find Usages in the popup menu).

 

14. 快速查看某个类或方法的文档描述,光标点中后请按Ctrl+Q

To quickly see the documentation for a class or method at caret, press Ctrl+Q (View | Quick Documentation).

 

15. 追溯类、方法、变量的源,进而查看他们的定义和实现代码,你可以按住Ctrl键然后鼠标点击这个类、方法、变量。这个你也许知道,但是如果没鼠标呢?请点击Ctrl+B,效果一样。

To navigate to the declaration of a class, method or variable used somewhere in the code, position the caret at the usage and press Ctrl+B (Navigate | Declaration). You can also click the mouse on usages with the Ctrl key pressed to jump to declarations.

 

16. 快速查看类内部架构。在VS和eclipse中,都有一个侧边窗口可以完成树状图来展示类的内部结构,idea则可以用快捷键完成。光标处于类中,按Ctrl+F12,就可以看到了。

注意,这里上方还提示了进一步的两个快捷键:

再按一下Ctrl+F12,显示所有继承下成员方法和变量:

 

再按一下:Ctrl + I,显示匿名类

可以选中其中的一个成员项,点击回车或F4进入定位。

You can quickly navigate in the currently edited file with Ctrl+F12 (Navigate | File Structure).

It shows the list of members of the current class. Select an element you want to navigate to and press the Enter key or the F4 key.

To easily locate an item in the list, just start typing its name.

 

 

17. 代码批量改名。如果你想对代码中一个已经存在变量或方法等改名,不需要重复地“查找+替换”。可以光标点中变量,然后按一下 Shift+F6。这时候,diea会推荐几个名称,可以选中其中一个就可以集体更改为推荐名称。

如果想自己改名,可以这样:这时候代码中的所有该变量底色变色,你在其中一处修改变量,其他地方会跟着变化。

如何你再按一次 Shift+F6,会出现一个比较正式的重命名对话框,类似于eclipse。并且,这里可以选择是否替换字符串和注释中的目标名称等。

You can easily rename your classes, methods and variables with automatic correction of all places where they are used.

To try it, place the caret at the symbol you want to rename, and press Shift+F6 (Refactor | Rename). Type the new name in the popup window that appears, or select one of the suggested names, and press Enter.

 

18. 儿子改老子的方法。如果在编写子类时,如果想覆盖父类中的方法,有快捷键 Ctrl+O,O就是Override。

如果是类想要实现接口中的某个方法,按Ctrl+I,I 就是Implement。

You may easily override methods of the base class by pressing Ctrl+O (Code | Override Methods).

To implement methods of the interfaces that the current class implements (or of the abstract base class), use Ctrl+I (Code | Implement methods).

 

19. 发现上下文中合适的方法或变量。光标所在位置,按Ctrl+Shift+空格,出现合适的匹配结果。这时候,你可能会问:“我记得Ctrl  + 空格 好像也是类似的功能啊?”

举个例子:加入我们输入了如下,光标位置如图:

Ctrl  + 空格 的效果如下:

Ctrl+Shift+空格 直接填充了一个。

所以,我们对一些相似但不相同的快捷键做个比较:

CTRL+SHIFT+SPACE 自动补全代码
CTRL+空格  代码提示
CTRL+ALT+SPACE  类 名或接口名提示

注意:

CTRL+SHIFT+SPACE 在匹配建议方法或变量的时候才会给出5个合适匹配结果的列表。

The SmartType code completion greatly helps to find methods and variables that are suitable in the current context, by analyzing the expected type of the whole expression. So doing, IntelliJ IDEA pinpoints the top five most suitable results and highlights them on the green background. For example, type

and press Ctrl+Shift+空格:

The SmartType completion also works after the return keyword, in an assignment, in an argument list of a method call and other places.

 

 

20. 将选中的代码语句自动构建在一个条件、选择、异常捕获等结构中。只要按Ctrl+Alt+T ,就可以构建多种代码段。

 

 

When you want to catch exceptions thrown by some code fragment, select it in the editor, press Ctrl+Alt+T (Code | Surround With) and choose try / catch. The catch blocks for all the exceptions thrown inside the block will be generated automatically.

You can customize the bodies of the generated catch blocks on the Code tab of File | Settings | File and Code Templates.

Use other items in the list to surround with other constructs.

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值