Intellj Idea 快捷键逐个详说(1)

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值