Intellj Idea 快捷鍵逐個詳說(1)

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.

相關文章
相關標籤/搜索