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

11. 自動代碼補全Ctrl+空格。與eclipse中的alt+/ ,VS中的 alt + 向右,相似。若是輸入的開頭對應的補全結果只有一個則直接自動補全類名、變量名等代碼,對應補全的結果有多個,則出現列表選擇。注意:Ctrl+空格與系統輸入法切換衝突(win8以上搜狗輸入法中英文切換,win7如下爲windows自身的輸入法切換快捷鍵),因此應把輸入代碼時的輸入法先換爲windows自身的英文輸入法,或者仍是更改idea的快捷鍵吧。express

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.windows

 

12. get set 等自動生成。按快捷鍵:alt+insert架構

 

13.迅速查找某個東西在項目中的全部出處,這個東西能夠是一個類、方法或者變量名稱等。app

只要你將光標點在上面,而後按Alt+F7。好比點中某個變量,按Alt+F7後,編輯區源代碼全部引用該變量的地方高亮顯示,idea下方彈出項目下查找結果列表。eclipse

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).ide

 

14. 快速查看某個類或方法的文檔描述,光標點中後請按Ctrl+Qui

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

 

15. 追溯類、方法、變量的源,進而查看他們的定義和實現代碼,你能夠按住Ctrl鍵而後鼠標點擊這個類、方法、變量。這個你也許知道,可是若是沒鼠標呢?請點擊Ctrl+B,效果同樣。code

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.

相關文章
相關標籤/搜索