1.無處不在的跳轉(zhuǎn)
注: 這里的快捷鍵是自己定義的,并非大家都一樣,可以通過find Action查找相應(yīng)的快捷鍵,我在這里只演示Mac系統(tǒng)下使用的快捷鍵,且大多數(shù)是默認(rèn)的.(windows平臺請?zhí)D(zhuǎn)友鏈)
項目之間的跳轉(zhuǎn): option+command+] 下一個項目; option+command+[ 上一個項目
查找操作: 菜單->Help->Find Action (command+shift+A)
查找最近瀏覽文件: Recent Files (command+E)
查找最近修改的文件: Recent Edited Files (command+shift+E)
跳轉(zhuǎn)到上次修改的地方: 菜單->Navigate->Last Edit Location (command+shift+delete)
跳轉(zhuǎn)到上/下次瀏覽(光標(biāo)停留)的地方: 菜單->Navigate->Back/Forward (option+command+←/→)
利用書簽跳轉(zhuǎn): F11添加刪除書簽; command+F11+數(shù)字可添加帶數(shù)字的書簽,使用control+數(shù)字可互相跳轉(zhuǎn)
收藏位置和文件: 查看收藏 command + 2; 添加收藏 option + shift + F (光標(biāo)在任意位置是收藏文件,光標(biāo)在方法名上是收藏方法)
-
字符跳轉(zhuǎn)插件 emacsIdea置跳轉(zhuǎn):
- 配置emacsIdeas快捷鍵(設(shè)置/keymap/emacIdeas下AceJumpWord添加對應(yīng)的快捷鍵| 按下剛配置的快捷鍵比如我control+F 再按下要找的字母| 輸入任意高亮位置字母就跳轉(zhuǎn)到對應(yīng)位置了)
-
編輯區(qū)和文件區(qū)來回跳轉(zhuǎn)
- 編輯區(qū) -> 文件區(qū) : command + 1
- 文件區(qū) -> 編輯區(qū) : Esc
利用vim進(jìn)行多編輯區(qū)跳轉(zhuǎn)(安裝IdeaVim插件之后,有興趣自行百度)
2.高速定位代碼
- 類:
- 菜單欄 →Navigate →Class(command+N) 其中include none..勾上就可以關(guān)聯(lián)到Jar包里所依賴的類
- 文件:
- 菜單欄 navigate →file(command+shift+N)
- 符號(方法和屬性):
- 菜單欄 navigate →symbol(command+option+shift+N)
- 字符串:
- 菜單欄 edit→find→find in path(control+shift+F)
3.代碼小助手:
3.1列操作
- 移動到當(dāng)前單詞尾部:
- find action →輸入move caret to next word (option+→)
- 選中到當(dāng)前單詞尾部 (shift+option+→)
- 當(dāng)前單詞設(shè)置大小寫切換:
- edit→toggle case (shift+command+U)
- 移動到當(dāng)前行首:
- find action→輸入move caret to line start (command+←)
- 移動到當(dāng)前行尾:
- find action→輸入move caret to line end (command+→)
- 將當(dāng)前行的操作應(yīng)用到相似行進(jìn)行批量操作:
- 菜單欄edit→find→select all occurrences (control+command+G)
★ 代碼格式化 (option+command+L)
3.2模板 Live Template
-
main
- findaction→輸入live templates→點擊右上角“+”
- 輸入縮寫main 簡介public static void main
- 輸入方法體
public static void main(String[] args) { $END$ }
- 點擊define→勾選java
- 輸入main敲下回車即可仗颈。
-
psfi
- 輸入最終模板(右邊var1、var2確保輸入一個參數(shù)回車后跳到另一參數(shù)輸入)
public static final int $var1$ = $var2$;
- 點擊define→勾選java
-
psfs
- 輸入最終模板(右邊var1、var2確保輸入一個參數(shù)回車后跳到另一參數(shù)輸入)
public static final String $var1$ = "$var2$";
- 點擊define→勾選java
-
pic
- 輸入模板 pic(private int 帶有注釋)
/** * $var1$ **/ private int $var2$; $End$
- 點擊define→勾選java
pi、ps(private int ..和private String..)設(shè)置同上,略。
3.3 postfix
- 使用此功能(神器,輸入一些東西加上"."后自動轉(zhuǎn)換成想要的模板)
- find action→postfix completion→勾選enable postfix completion.
- 找到j(luò)ava→fori可以查看實現(xiàn)原理(下面僅列出幾種常用的)。
- find action→postfix completion→勾選enable postfix completion.
- for循環(huán)(fori)
- 打印(sout)
- field
- 構(gòu)造方法中.field會自動補充不存在的字段(前提是構(gòu)造方法的形參列表帶這個字段和類型)
- return
- nn(判斷是否為空)
3.4 option+enter
- 快捷鍵
- find action→show intention actions (option+enter)
- 自動創(chuàng)建方法
- list replace(作為形參傳進(jìn)方法的list,通過"list.for"+enter可生成for循環(huán)遍歷list,意義不大)
- 字符串format或者build
- 實現(xiàn)接口
- 新建接口→UserService→光標(biāo)定位到接口名稱→按下option+enter
- 選擇implement interface→輸入實現(xiàn)類名稱+選擇創(chuàng)建位置
- 選擇實現(xiàn)接口中的方法即可生成梯啤。
- 單詞拼寫
- 如果單詞不記得如何拼寫可以選中再按下option+enter選擇type change to它提示的英文單詞進(jìn)行矯正。
- 導(dǎo)包 ★
- 通過提示手動導(dǎo)包
- 按下option+enter即可
- 自動導(dǎo)包
- Settings→Editor→general→勾上auto import Optimize...
- 通過提示手動導(dǎo)包
4.編寫高質(zhì)量代碼
- 重構(gòu)變量
- 選中要重構(gòu)的變量→菜單欄選擇refactor→rename (shift+F6)
- 重構(gòu)方法
- 選擇要重構(gòu)的方法名→菜單欄選擇refactor→change signature (command+F6)→輸入相關(guān)參數(shù)配置即可存哲。
- 另一種通過option+enter
- 直接在調(diào)用時輸入要添加的參數(shù)→option+enter →add 相應(yīng)參數(shù)至方法即可因宇。
- 抽取
- 抽取變量
- 選中字符串中的變量→refactor→extract→variable(option+command+V);
- 抽取靜態(tài)變量
- 選中字符串中變量→refactor→extract→Constant(option+command+C)
- 抽取方法參數(shù)
- 如果方法中有用到成員變量(如this.name)→refactor→extract→parameter(option+command+P)就可以將成員變量以入?yún)⒌男问絺鬟M(jìn)來七婴。
- 抽取函數(shù)
- 將方法中的邏輯抽取為一個方法 refactor→extract→Method(option+command+M)
- 抽取變量
5.尋找修改軌跡
5.1 git集成
- annotate
- 找出某行代碼作者是誰
- 在代碼行左側(cè)右擊annotate
- 找出某行代碼作者是誰
- 移動所有改動之處
- find action→previous changes (control+option+shift+向上箭頭)
- 撤銷操作
- find action→ revert (option+command+Z)
5.2 local history★
- 顯示本地修改歷史記錄
- find action→local history→show history
- 點擊箭頭可撤銷。
- put label(類似commit提交注釋的功能)
6.關(guān)聯(lián)一切
6.1 與Spring的關(guān)聯(lián)
- 視頻學(xué)習(xí)鏈接
- 操作流程
- file→project structure→facets→點擊“+”→Spring到項目→點左下角加號→再勾上Spring配置文件即可(可以看到Springbean被哪里定義等信息)察滑。
6.2 與數(shù)據(jù)庫的關(guān)聯(lián)
- 數(shù)據(jù)庫連接
- view→tool windows→database
- 按“+”→datasource→mysql→輸入數(shù)據(jù)庫名本姥;用戶名、密碼測試連接出現(xiàn)Suqcessful即可
7.調(diào)試程序
7.1 斷點調(diào)試
- 打斷點
- run→toggle line breakpoint(command+F8)
- 運行Debug模式
- run→debug...(shift+F9)或者按小蟲子
- 按步運行
- step over(F8)
- 跳過斷點
- resume program(F9)
- 查看所有斷點
- run→view breakpoints(command+shift+F8)
- 禁止所有斷點
- debug窗口中左側(cè)找到禁止標(biāo)志(mute breakpoints)→F9跳過所有斷點
- 條件斷點
- 在斷點上右擊出現(xiàn) condition 輸入條件(如s.equals("wuqingvika"))
- 表達(dá)式求值
- 查看值★
- run→evaluate expression(option+F8)
- 查看值★
- 運行到指定行
- 在Debug窗口找到有個光標(biāo)圖標(biāo) run to cursor(option+F9)
- setValue★
- 在debug中只要選中(Variables中)要設(shè)置的變量按下F2設(shè)定想要設(shè)定的值即可杭棵。
7.2 任一處運行
- 運行當(dāng)前上下文
- find action→debug context (control+shift+F9)就會運行光標(biāo)就近處的方法
- 注:如果光標(biāo)在中間 那么兩個都會運行
- 在當(dāng)前可運行列表中選擇一個運行
- option+shift+F9
- 編輯當(dāng)前運行
- run→edit configurations→application→選擇某個應(yīng)用程序→在program arguments輸入?yún)?shù)信息
8.其他操作
8.1 文本操作
- 復(fù)制文件名
- 直接點擊文件名 command+c在文本編輯區(qū)command+v即可(或選中文件按F5)。
- 復(fù)制文件全名
- shift+command+c 再ctrl+v即可氛赐。
- 復(fù)制多個文件名
- 多次command+c 再shift+command+v選擇要復(fù)制哪些文件名即可魂爪。
- 結(jié)構(gòu)圖
- 查看當(dāng)前field、method大綱
- navigate→File Structure(command+F12)
- 查看maven依賴★
- pom.xml中右擊選Maven→show dependencies可以看到所有的依賴關(guān)系艰管。
- 可以按command+f進(jìn)行搜索
- 可以右擊exclude進(jìn)行排除
- pom.xml中右擊選Maven→show dependencies可以看到所有的依賴關(guān)系艰管。
- 查看類圖★
- 普通的子類名右擊Diagrams→Show diagram(option+shift+command+U)即可出現(xiàn)類圖滓侍。
- 查看類繼承結(jié)構(gòu)★
- find action→hierarchy actions→hierarchy(command+8)
- 方法調(diào)用層次★
- find action→call hierarchy(control+option+H)
- 查看當(dāng)前field、method大綱
致謝
該筆記總結(jié)自慕課網(wǎng)視頻教程,感謝老師@簡書閃電俠,受益匪淺,傳送門