在使用IntelliJ Idea的時候,使用快捷鍵是必不可少的。掌握一些常用的快捷鍵能大大提高我們的開發(fā)效率。有些快捷鍵可以熟練的使用,但是還有另外一些快捷鍵雖然很好用,但是由于因為沒有形成使用習(xí)慣或者沒有理解快捷鍵的用法,甚至之前對一些快捷鍵根本沒有概念,導(dǎo)致不會去使用。對于這些快捷鍵,如果能夠用好,編輯代碼的效率必能提高一個水平。所以在此梳理出來,加強自己的使用,形成習(xí)慣。
(注:有些操作的快捷鍵做了更改,和IntelliJ Idea默認的快捷鍵不一樣)
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Move Caret to Code Block End | Ctrl+] | 諸如{}圍起來的代碼塊,使用該快捷鍵可以快速跳轉(zhuǎn)至代碼塊的結(jié)尾處 |
| Move Caret to Code Block Start | Ctrl+[ | 同上,快速跳至代碼塊的開始出 |
| Complete Current Statement | Ctrl+Shift+Enter | 將輸入的if、for、函數(shù)等等補上{}或者;使代碼語句完整 |
| Start New Line | Shift+Enter | 在當(dāng)前行的下方開始新行 |
| Start New Line Before Current | Ctrl+Alt+Enter | 在當(dāng)前行上方插入新行 |
| Delete to Word End | Ctrl+Delete | 刪除光標所在至單詞結(jié)尾處的所有字符 |
| 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 | 復(fù)制 |
| Paste | Ctrl+V | 粘貼 |
| Join Lines | Ctrl+Shift+J | 將選中的行合并成一行 |
----------------Find-----------------
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Find | Ctrl+F | 在當(dāng)前文件中查找 |
| Replace | Ctrl+R | 替換字符串 |
| Find in Path | Ctrl+Shift+F | 在全局文件中查找字符串 |
| Replace in Path | Ctrl+Shift+R | 在全局中替換字符串 |
| Find Usages | Alt+F7 | 查找當(dāng)前變量的使用,并列表顯示 |
| Show Usages | Ctrl+Alt+F7 | 查找當(dāng)前變量的使用,并直接對話框顯示 |
| Find Usages in File | Ctrl+F7 | 在文件中查找符號的使用 |
| Highlight Usages in File | Ctrl+Shift+F7 | 在文件中高亮顯示變量的使用 |
這里的快捷鍵用的頻率還是很高的,但是之前用的最多的是Ctrl+F和Ctrl+Shift+F,后面相關(guān)的Find Usages基本上沒有用過,后面應(yīng)該多使用,有的時候相對Ctrl+F在文件內(nèi)按字符串查找,還是更好用一些
------------------------------------------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 | 定位至選中類或方法的具體實現(xiàn) |
| Type Declaration | Ctrl+Shift+B | 直接定位至光標所在變量的類型定義 |
| Super Method | Ctrl+U | 直接定位至當(dāng)前方法override或者implements的方法定義處 |
| File Structure | Ctrl+F12 | 顯示當(dāng)前文件的文件結(jié)構(gòu) |
| File Path | Ctrl+Alt+F12 | 顯示當(dāng)前文件的路徑,并可以方便的將相關(guān)父路徑打開 |
| Type Hierarchy | Ctrl+H | 顯示當(dāng)前類的繼承層次 |
| Method Hierarchy | Ctrl+Shift+H | 顯示當(dāng)前方法的繼承層次 |
| Call Hierarchy | Ctrl+Alt+H | 顯示當(dāng)前方法的調(diào)用層次 |
| Next Highlighted Error | F2 | 定位至下一個錯誤處 |
| Previous Highlighted Error | Shift+F2 | 定位至前一個錯誤處 |
| Previous Occurrence | Ctrl+Alt+向上箭頭 | 查找前一個變量共現(xiàn)的地方 |
| Next Occurrence | Ctrl+Alt+向下箭頭 | 查找下一個變量共現(xiàn)的地方 |
目前還不知道Previous Occurrence 和 Next Occurrence是怎么用的,在變量上使用沒有反應(yīng)。不過在Edit--Find菜單下有幾個菜單項:Find Next / Move to Next Occurrence、Find Previous / Move to Previous Occurrence等。當(dāng)選中變量的時候,需要首先點擊“Find Word at Caret”,然后再點擊上述選項才有用
-----------------------------------------------Code----------------------------------------
| 動作 | 快捷鍵 | 說明 |
|---|---|---|
| Override Methods... | Ctrl+O | 重寫基類的方法 |
| Implement Methods... | Ctrl+I | 實現(xiàn)基類或接口中的方法 |
| Generate... | Alt+Insert | 產(chǎn)生構(gòu)造方法、getter/setter等方法 |
| Surround With... | Ctrl+Alt+T | 將選中的代碼使用if、while、try/catch等包裝 |
| Unwrap/Remove... | Ctrl+Shift+Delete | 去除相關(guān)的包裝代碼 |
-----------------------------------------------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 | 優(yōu)化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 | 更改函數(shù)簽名 |
| Type Migration | Ctrl+Shift+F6 | 更改類型 |