Resharper、Rider 功能紀錄 === ###### tags: `Visual Studio` `Resharper` [TOC] # 前言 > 習慣快捷鍵的開發效率,如虎添翼。 :::warning VS + Resharper 開大專案速度慢到無法忍受了,已轉到 Rider。 Rider 快捷鍵(VS) https://resources.jetbrains.com/storage/products/rider/docs/Rider_VS_win_shortcuts.pdf ::: # Rider 快捷鍵(VS) ## 指令 ### .var 數值後面打 ``.var``,再按下 ``tab`` 可以新增變數 ```csharp= "xxx".var // after press down 'tab' var xxx = "xxx"; ``` ``.if`` 同理 ## 幫助視窗 Run Everything: Ct * 3 打開方案總管: Ct Al L、Al 1 Favorities Window: Al 2 Find Window: Al 3 Commit Window(自訂): Al 4 查看快速修改建議: Al Enter 導覽建議: Al ~ 查看檔案結構(可拖拉移動方法位置、增加刪除 Region): Ct Al F 重構建議: Ct Sh R 剪貼簿歷史: Ct Sh V 設定: Ct Al S ### 快速選擇 按著 ``alt`` 再按底線的字母,即可快速選擇 :::info 若功能沒有出現底線,可以先按一下 ``alt`` ::: ## 快速定位 任意查詢: Ct T 當前文件中查詢: Al \\ 查詢檔案/資料夾: Ct Sh T 查詢方案名稱: Ct Al Sh T 移至行數: Ct G 回到最近編輯處(Last edit location): Ct Sh BackSpace 查看最近幾次編輯紀錄: Ct Sh E 查看最近幾次編輯檔案: ``Ct Sh ,`` 方案總管定位到當前文件: Al Sh L 字串 Global 查詢(Find in Files): Ct Sh F Jump to Navigation Bar: Ct F2 ## 引用 查看引用: Sh F12、Sh Al F12 預覽定義: Al F12 Highlight Usage: Al Sh F11 查看方法參數(Parameter info): (預設) Ct Sh Space,(自訂) Al i 引用導航: Ct 滑鼠點方法 ## 移動 移至上/下一個成員(Next Method): Al 上/下 Move Line Up/Down(自訂): Ct Al 上/下 Move Statement Up/Down: Ct Al Sh 上/下 Move Element Left/Right: Ct Al Sh 左/右 切換頁籤: Ct Tab(按住) 向左/右切換頁籤: Al 左/右 上/下一步(Forward、Back): ``Ct -``、``Ct Sh -`` 畫面上下滾動(Scroll Up/Down): Ct 上/下 畫面左右滾動(Scroll Left/Right): (自訂) Al Sh 左/右 移至上/下一個錯誤: Al PageUp/PageDown 到行首、尾: Home、End(Al Sh G) 到文件首、尾: Ct Home、Ct End 到當前可視區域的最上方: Ct PageUp 到當前可視區域的最下方: Ct PageDown 移到下個相同字串(next occurrence of the word at caret): Ct F3 Move caret to code block start: ``Al Sh [`` Move caret to code block start with selection: ``Al Sh Ct [`` Move caret to code block end with selection: ``Al Sh Ct ]`` AceJump: (預設) ``Ct ;``,(自訂)``Al ;`` ## 編輯 向上/下長出游標(Clone Caret with Virtual Space): Al Sh 上/下 自訂位置長出游標(Add or Remove Caret): Ct Al 滑鼠點擊 插入下一個相符字串游標(Add selection for next occurrence): ``Al Sh .`` (取消一次 ``Al Sh ,``) 插入程式碼 Generate (Ctor、繼承的方法、設定屬性): Al Insert 新增檔案 New in This Directory (Class、Interface、Controller...etc): Ct Al Insert 插入命令 Live Template Insert(for、if、switch...etc): Ct E L 插入區塊 SurroundWith (Region、if): Ct E U 開啟行上方(向上插入行): Ct Enter 開啟行下方(向下插入行): Ct Sh Enter 複製行(編輯.複製): Ct D 剪下行: Ct X 刪除行: Ct L 縮排: Tab 減少縮排: Sh Tab 取代文字(Replace): Ct H 選取: Sh (Home、End、上/下/左/右) 選取的文字變大小寫(Toggle Case): Ct Sh U Cyclic Expand Word(補齊字串): ``Al /`` Extend selection: Ct Al 右 or Ct W(游標在中間也可選取文字) Shrink selection: Ct Al 左 : ## 書籤 書籤視窗: Ct ~ ![](https://i.imgur.com/Z1vgE5W.png) 增加/取消書籤(自訂): Al Sh 0~9 移至書籤: Ct 0~9 ## 重構 重新命名: Ct R R 安全刪除: Ct R D 提取方法(先選取): Ct R M 自動排版: Ct K D ### 推薦 Change Signature Introduce variable/field/parameter Pull/Push Member Up/Down Rename Extract method Inline variable/field/parameter/method Generate code Reformat Duplicate code ## 設定 ### File Tabs 多列 預設所有開啟的檔案都會再同一列,超過就會有 X 卷軸,但個人習慣把常用的檔案 Pin 起來,並且整個檔案名稱都要完整顯示,所以可能會有好幾行,這種情況就要把紅框處取消打勾。 ![](https://i.imgur.com/sf9S5mA.jpg) # VS Code & Resharper(封存) ## 幫助視窗 打開 Resharper 選單: Al R 查看快捷鍵: Ct * 3 打開方案總管: Ct Al L (舊 Ct Sh E) 查看快速修改建議: Al Enter 導覽建議: Al ~ 檢查視窗(可查看變數所有賦值處): Al Sh ~(原 Ct Al Sh A) 查看檔案結構(可拖拉移動方法位置、增加刪除 Region): Ct Al F 重構建議: Ct Sh R VS 快捷鍵設定: Ct K Ct S ### 快速選擇 按著 ``alt`` 再按底線的字母,即可快速選擇 :::info 若功能沒有出現底線,可以先按一下 ``alt`` ::: 幫助視窗 ![](https://i.imgur.com/ch1kDw3.png) ![](https://i.imgur.com/hn8v4zo.png) ## 快速定位 任意查詢: Ct T 當前文件中查詢: Al \\ 查詢檔案/資料夾: Ct Sh T 查詢方案名稱: Al Sh T 移至行數: Ct G 回到最近編輯處(Last edit location): Ct Sh BackSpace 查看最近幾次編輯紀錄: Ct Sh , 查看最近幾次編輯檔案: Ct Sh . 方案總管定位到當前文件: Al Sh L ## 引用 查看引用: Sh F12、Sh Al F12 預覽定義: Al F12 Highlight Usage: Al Sh F11 查看方法參數: Al Sh i 引用導航: Ct 滑鼠點方法 ## 移動 移至上/下一個成員(GotoPrevMember): Ct Al 上/下 選取行向上/下移動: Al 上/下 切換頁籤: Ct Tab(按住) 畫面上下滾動: Ct 上/下 移至上/下一個警告: Al PageUp PageDown 移至上/下一個錯誤: Al Sh PageUp PageDown 到行首、尾: Home、End 到文件首、尾: Ct Home、Ct End 到當前可視區域的最上方: Ct PageUp 到當前可視區域的最下方: Ct PageDown ## 編輯 向上/下長出游標(向上/下延伸一行的資料行): Al Sh 上/下 自訂位置長出游標: Ct Al 滑鼠點擊 插入程式碼 Generate (Ctor、繼承的方法、設定屬性): Al Insert 插入模板 Generate File (Class、Interface、Controller...etc): Ct Al Insert 插入命令 Live Template Insert(for、if、switch...etc): Ct E L 插入區塊 SurroundWith (Region、if): Ct E R 開啟行上方(向上插入行): Ct Sh Enter 開啟行下方(向下插入行): Ct Enter 複製行(編輯.複製): Ct Sh D 刪除行: Ct Sh K 插入下一個相符的游標: Ct D 縮排: Tab 減少縮排: Sh Tab 選取: Sh (Home、End、上/下/左/右) 選取的文字變大寫: Ct Sh U 選取的文字變小寫: Al U (VS 原生)選取目前文字 (推薦Resharper,可以 Shrink) Extend selection: Ct Al 右 Shrink selection: Ct Al 左 ## 書籤 書籤視窗: Ct ~ ![](https://i.imgur.com/Z1vgE5W.png) 增加/取消書籤: Al 0~9 移至書籤: Ct 0~9 ### 書籤視窗打不開 有時會發生無法打開書籤視窗的狀況,解決方法是直接清除所有書籤。 ![](https://i.imgur.com/GXTAHsC.png) ## 重構 重新命名: Ct R R 安全刪除: Ct R D 提取方法(先選取): Ct R M 自動排版: Al Sh F # 效能改善 預設會開啟方案分析(Solution Wide Analysis),沒有必要可以關掉(Resharper>Option>Code Inspection>Settings>Enable solution-wide analysis) # 已知問題 疑似 VS 2019 16.11.1(以後) + Resharper 2021.2.1 在某些情況下,右下角會一直跳出這個訊息,不斷出現&消失 > Sync solution: Roslyn projects changed but no projects saved ![](https://i.imgur.com/A0SfYKy.png) 參考[此篇](https://stackoverflow.com/questions/61371290/how-to-disable-resharper-messages-in-vs-2019-statusbar),關閉「Read solution directly from project/solution files.」後,就沒有再出現過提示訊息。 ![](https://i.imgur.com/UIfvx1V.png) # 參數提示 ![](https://i.imgur.com/AdB6eZb.png) ![](https://i.imgur.com/mowMGOf.png) ![](https://i.imgur.com/BXeRiUr.png) # Debug 第三方程式碼 記得先把工具 > 選項 > 一般 > 啟用 Just My Code 取消勾選。 ![](https://i.imgur.com/BW6iR6h.png) ![](https://i.imgur.com/8Ghm5EX.png) VS 其他不需要特別設定,交給 Resharper 裝好後的預設設定就好 ![](https://i.imgur.com/2F81MX6.png) ![](https://i.imgur.com/Duasb29.png) 正常情況下,直接 F12 進去 Source Code 裡面下中斷點,然後載入要 Debug 的 Dll 符號,之後就可以順利進入 Debug 了。 Debug 狀態下 > 偵錯 > 視窗 > 模組 ![](https://i.imgur.com/sIClFnr.png) ![](https://i.imgur.com/QVMkrqr.png) ## 沒有 PDB https://www.jetbrains.com/help/resharper/Debugging_Without_Source_Code.html https://www.jetbrains.com/help/resharper/Generating_PDB_Files.html # Debug Highlight Resharper 其中一個好用的功能就是在 Debug 時,能夠直接在變數旁邊顯示值,若是類別也可以直接點開看內容 ![](https://i.imgur.com/WMEAT87.png) ![](https://i.imgur.com/qbTrwcM.png) 另外還有一個有用的小技巧,可以直接 Highlight 你想看的欄位 EX: 有 10 筆客戶資料 ![](https://i.imgur.com/1pIEwgv.png) 選擇想 Highlight 的欄位 > 右鍵 > Highlight Property。 以此處為例,我只想看客戶的 ID 而已,不想每個都點進去看 ![](https://i.imgur.com/lac8WtF.png) 設定好後,效果圖下 ![](https://i.imgur.com/fkzcLDV.png) 甚至是接下來 foreach 存取時,可以直接看到當前遍歷的 ClientID,也少了滑鼠移動到 clientVM > 點開 > 看 ClientId 的這些動作 ![](https://i.imgur.com/xCUTwYD.png) # ScrollBar VS 預設垂直捲軸(Y軸)點了以後,畫面不會直接跳到那邊,而是向上/向下捲動一點而已,如果想要點了直接跳到該位置,要調整成「地圖模式」(設定>文字編輯器>所有語言>捲軸)。 ![](https://i.imgur.com/nz0Jofs.png) 不想要顯示模糊程式碼,如上圖把「原始檔概觀」關閉就好。 ![](https://i.imgur.com/bLBOpZU.png) ![](https://i.imgur.com/0XTO7xp.png) # 方案總管定位到當前文件 VS 內建功能,不需要按快捷鍵,開啟設定後,方案總管會自動定位到當前編輯器開啟的檔案,不需要再方案總管裡面大海撈針了。 ![](https://i.imgur.com/revnI4O.png) # 設定檔 以上設定匯出如下,可以直接匯入使用 ### VS 2019 16.9 [匯出教學](https://docs.microsoft.com/zh-tw/visualstudio/ide/identifying-and-customizing-keyboard-shortcuts-in-visual-studio?view=vs-2022) - 2021/11/09 https://drive.google.com/file/d/1r33NzBoQD1k1Tju-bXBdgr1zJlh76TCX/view?usp=sharing ### Resharper 2021.1.2 - 2021/11/09 https://drive.google.com/file/d/1oSst3b1CFIX8zzXyCPylxXq1S2_F1kMO/view?usp=sharing # 參考 https://ldqk.org/21 [官方文檔](https://www.jetbrains.com/help/resharper/) [快捷鍵 PDF](https://www.jetbrains.com/resharper/docs/ReSharper_DefaultKeymap_VSscheme.pdf)