IDEA 的高效使用
- 常用快捷鍵
- idea中查看方法的呼叫鏈
常用快捷鍵
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Move Caret to Code Block End | Ctrl+] | 諸如{}圍起來的代碼塊,使用該快捷鍵可以快速跳轉至代碼塊的結尾處 |
| Move Caret to Code Block Start | Ctrl+[ | 同上,快速跳至代碼塊的開始出 |
| Complete Current Statement | Ctrl+Shift+Enter | 將輸入的if、for、函式等等補上{}或者;使代碼陳述句完整 |
| Start New Line | Shift+Enter | 在當前行的下方開始新行 |
| Start New Line Before Current | Ctrl+Alt+Enter | 在當前行上方插入新行 |
| Delete to Word End | Ctrl+Delete | 洗掉游標所在至單詞結尾處的所有字符 |
| Delete to Word Start | Ctrl+BackSpace | 洗掉游標所在至單詞開頭的所有字符 |
| Move Caret to Previous Word | Ctrl+向左箭頭 | 將游標移至前一個單詞 |
| Move Caret to Next Word | Ctrl+向右箭頭 | 將游標移至后一個單詞 |
| Scroll Up | Ctrl+向上箭頭 | 向上滾動一行 |
| Scroll Down | Ctrl+向下箭頭 | 向下滾動一行 |
| Extend Selection | Ctrl+W | 選中整個單詞 |
| Toggle Case | Ctrl+Shift+U | 切換大小寫 |
———————————————Edit——————————————————–
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Undo | Ctrl+Z | 撤銷 |
| Redo | Ctrl+Shift+Z | 重做 |
| Cut | Ctrl+X | 剪切 |
| Copy | Ctrl+C | 復制 |
| Paste | Ctrl+V | 粘貼 |
| Join Lines | Ctrl+Shift+J | 將選中的行合并成一行 |
—————-Find—————–
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Find | Ctrl+F | 在當前檔案中查找 |
| Replace | Ctrl+R | 替換字串 |
| Find in Path | Ctrl+Shift+F | 在全域檔案中查找字串 |
| Replace in Path | Ctrl+Shift+R | 在全域中替換字串 |
| Find Usages | Alt+F7 | 查找當前變數的使用,并串列顯示 |
| Show Usages | Ctrl+Alt+F7 | 查找當前變數的使用,并直接對話框顯示 |
| Find Usages in File | Ctrl+F7 | 在檔案中查找符號的使用 |
| Highlight Usages in File | Ctrl+Shift+F7 | 在檔案中高亮顯示變數的使用 |
這里的快捷鍵用的頻率還是很高的,但是之前用的最多的是Ctrl+F和Ctrl+Shift+F,后面相關的Find Usages基本上沒有用過,后面應該多使用,有的時候相對Ctrl+F在檔案內按字串查找,還是更好用一些
—————————————–Navigate————————————————
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Class… | Ctrl+N | 查找類檔案 |
| File… | Ctrl+Shift+N | 查找檔案 |
| Line… | Ctrl+G | 定位到檔案某一行 |
| Back | Alt+向左箭頭 | 回傳至上次游標位置 |
| Forward | Alt+向右箭頭 | 回傳至后一次游標位置 |
| Last Edit Location | Ctrl+Shift+Backspace | 回傳上次編輯位置 |
| Next Edit Location | Ctrl+Shift+反斜杠 | 回傳后一次編輯位置 |
| Declaration | Ctrl+B | 定位至變數定義的位置 |
| Implementation(s) | Ctrl+Alt+B | 定位至選中類或方法的具體實作 |
| Type Declaration | Ctrl+Shift+B | 直接定位至游標所在變數的型別定義 |
| Super Method | Ctrl+U | 直接定位至當前方法override或者implements的方法定義處 |
| File Structure | Ctrl+F12 | 顯示當前檔案的檔案結構 |
| File Path | Ctrl+Alt+F12 | 顯示當前檔案的路徑,并可以方便的將相關父路徑打開 |
| Type Hierarchy | Ctrl+H | 顯示當前類的繼承層次 |
| Method Hierarchy | Ctrl+Shift+H | 顯示當前方法的繼承層次 |
| Call Hierarchy | Ctrl+Alt+H | 顯示當前方法的呼叫層次 |
| Next Highlighted Error | F2 | 定位至下一個錯誤處 |
| Previous Highlighted Error | Shift+F2 | 定位至前一個錯誤處 |
| Previous Occurrence | Ctrl+Alt+向上箭頭 | 查找前一個變數共現的地方 |
| Next Occurrence | Ctrl+Alt+向下箭頭 | 查找下一個變數共現的地方 |
目前還不知道Previous Occurrence 和 Next Occurrence是怎么用的,在變數上使用沒有反應,不過在Edit–Find選單下有幾個選單項:Find Next / Move to Next Occurrence、Find Previous / Move to Previous Occurrence等,當選中變數的時候,需要首先點擊“Find Word at Caret”,然后再點擊上述選項才有用
————————————————-Code———————————————–
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Override Methods… | Ctrl+O | 重寫基類的方法 |
| Implement Methods… | Ctrl+I | 實作基類或介面中的方法 |
| Generate… | Alt+Insert | 產生構造方法、getter/setter等方法 |
| Surround With… | Ctrl+Alt+T | 將選中的代碼使用if、while、try/catch等包裝 |
| Unwrap/Remove… | Ctrl+Shift+Delete | 去除相關的包裝代碼 |
—————————————–Completion——————————————
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Basic | Alt+/ | 自動完成 |
| SmartType | Alt+Enter | 自動提示完成 |
—————————————-Folding————————————————-
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Expand | Ctrl+= | 展開代碼 |
| Collapse | Ctrl± | 收縮代碼 |
| Expand Recursively | Ctrl+Alt+= | 遞回展開代碼 |
| Collapse Recursively | Ctrl+Alt± | 遞回收縮代碼 |
| Expand All | Ctrl+Shift+= | 展開所有代碼 |
| Collapse All | Ctrl+Shift± | 收縮所有代碼 |
———————————
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Insert Live Template | Ctrl+J | 插入Live Template |
| Surround with Live Template | Ctrl+Alt+J | 使用Live Template包裝 |
| Comment with Line Comment | Ctrl+/ | 使用//進行注釋 |
| Comment with Block Comment | Ctrl+Shift+/ | 使用/**/進行注釋 |
| Reformat Code | Ctrl+Alt+L | 格式化代碼 |
| Auto-Indent Lines | Ctrl+Alt+I | 自動縮進行 |
| Optimize Imports | Ctrl+Alt+O | 優化import |
———————————
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Move Statement Down | Ctrl+Shift+向下箭頭 | 將游標所在的代碼塊向下整體移動 |
| Move Statement Up | Ctrl+Shift+向上箭頭 | 將游標所在的代碼塊向上移動 |
| Move Element Left | Ctrl+Alt+Shift+向左箭頭 | 將元素向左移動 |
| Move Element Right | Ctrl+Alt+Shift+向右箭頭 | 將元素向右移動 |
| Move Line Down | Alt+Shift+向下箭頭 | 將行向下移動 |
| Move Line Up | Alt+Shift+向上箭頭 | 將行向上移動 |
————————————-Refactor——————————————–
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Rename | Shift+F6 | 重命名 |
| Change Signature | Ctrl+F6 | 更改函式簽名 |
| Type Migration | Ctrl+Shift+F6 | 更改型別 |
idea中查看方法的呼叫鏈
- IntelliJ IDEA中可以在主選單中選擇Navigate | Call Hierarchy命令查看一個Java方法呼叫樹(caller和callee兩個方向),但是不像Eclipse那樣可以查看類成員變數的呼叫樹,

如下圖,左上角的兩個按鈕是呼叫和被呼叫關系的顯示,

- IntelliJ IDEA中可以在主選單中選擇Analyze | Dataflow from/to Here兩個命令查看運算式、變數和方法引數的傳遞關系樹,
Analyze | Data Flow to Here

Analyze | Data Flow from Here


- IntelliJ IDEA的"Find Usage"可以查看一個Java類、方法或變數的直接使用情況,


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/292919.html
標籤:其他
