在 VS IDE 用了 Vim 一段時間了,現在我要將 VS IDE 的 Vim 設定搬到 Rider,以下是我的設定步驟
下圖出自:https://blog.csdn.net/qq_42239765/article/details/103874859?utm_medium=distribute.pc_relevant.none-task-blog-title-3&spm=1001.2101.3001.4242
IdeaVim
安裝
Settings -> Plugins -> 搜尋 vim
裝好之後重新啟動 Rider
在 IDE 的右下角可以找到 IdeaVim 的 Icon,執行畫面如下:
自訂 Vim 啟用/停用 熱鍵
在某些情境需要關閉 Vim,比如說多攔選取,Vim 就需要停用,我想和 Vistual Studio 的設定一樣都是 Ctrl + Shift + F12,
設定步驟,在 Rider -> Ctrl+Alt + s -> 選擇 Keymap -> Vim Emulator -> Add Keyboard Shortcut
自訂 Vim 熱鍵
它會讀取 %UserProfile%/.ideavimrc;如果檔案不存在,會跳出以下視窗讓你選擇,vim 的熱鍵設定就只是一個文字檔
按鍵對映
主要有 map,noremap,unmap,mapclear四個 命令,並且有四個字首i,c,n,v修飾
四個命令
- nore:非遞迴
- map:遞迴的對映
如果 a 鍵被對應成了 b 鍵,c 鍵又被對應成了 a 鍵,遞迴對應會將,c 鍵對應成 b 鍵 - unmap:刪除某個對映
- mapclear:清除對映
四種修飾
- n:一般模式下生效
- v:可視模式下生效
- i:插入模式下生效
- c:命令列模式下生效
如何定義
以下是我常在用的部分熱鍵,將它貼到 .ideavimrc
"設定前贅詞
let mapleader=','
"載入vim設定檔
nmap <Leader>so :source C:\Users\yao\.ideavimrc<CR>
"設定搜尋時高亮顯示
set incsearch
"設定搜尋後高亮顯示
set hlsearch
"清除高亮搜尋
nnoremap <Leader>sc :nohlsearch<CR>
inoremap <Leader>sc <Esc>:nohlsearch<CR>
"顯示相對座標
"set relativenumber
set number
"顯示命令
set showmode
"<Ctrl><f>視窗往下捲一頁
nnoremap <Leader>f <C-f>
"<Ctrl><b>視窗往上捲一頁
nnoremap <Leader>b <C-b>
"<Ctrl><d>視窗往下捲半頁
nnoremap <Leader>d <C-d>
"<Ctrl><u>視窗往上捲半頁
nnoremap <Leader>u <C-u>
"<Ctrl><e>視窗往下捲一行
nnoremap <Leader>e <C-e>
"<Ctrl><y>視窗往上捲一行
nnoremap <Leader>y <C-y>
"退出目前文件
nnoremap <Leader>q :q!<CR>
"退出所有文件
nnoremap <Leader>Q :qa!<CR>
"複製目前單字到寄存器 o
nnoremap <Leader>y mo"+yiw"ayiw
Rider Action 對映
除了可以針對 Vim 對應熱鍵,也可以對應 Rider 的 Action,這裡的關鍵就在於怎麼找出 Rider 的 Action
在一般模式下,輸入 :actionlist
他會將所有的 Action 呈現出來,可以複製到記事本,比較好查看
若要查詢某一個功能,但不知道它的完整名稱,:actionlist xxx,xxx 指的就是查詢字串,我以 File Member 為例,這個功能是列出目前檔案有哪些成員
功能選單是 Navigate -> File Member
用 Ctrl + Shift + A 找 File Member
我直覺想到
:actionlist member
:actionlist file
最後,在 :actionlist file ,看到 Rider 的熱鍵 Alt + \,FileStructurePopup 就是 File Member 的指令
最後,把它放到 .ideavimrc,存檔
"顯示檔案成員
nmap ,m :action FileStructurePopup<CR>
切換到 Rider 的編輯畫面,輸入 ,so 載入新的設定,輸入 ,m
參考:
https://github.com/JetBrains/ideavim
Relative Line Numbers
使用 Vim 還需要相對座標,除了使用 set relativenumber 之外,還可以安裝以下套件,這個套件在 Plugins 找不到,需要到網頁下載,手動安裝
https://plugins.jetbrains.com/plugin/7414-relative-line-numbers/versions
安裝結果如下:右邊白色的 Number,是 Vim 的相對座標,左邊則是絕對座標
如果不喜歡它內建的顏色,還可以變更顏色,輸入 Ctrl + Alt + S 搜尋 VCS,找到 Color Scheme -> VCS Annotations -> Foregrond
Rider 2020.3 之後的版本,已經不支援這個套件,目前的解法還是使用 IdeaVim 的座標,我啟用混用座標
完整
:set number relativenumber
簡寫
:set nu rnu
停用
:set number! relativenumber!
:set nu! rnu!
AceJump
除了用 IdeaVim 定位之外,還可以使用 AceJump
安裝
Settings -> Plugins -> 搜尋 AceJump,安裝它
Ctrl + ; 開啟 AceJump 模式,輸入 s ,這裡你可以換成你想定位的內容,可以從下圖看到 s 已經有標上額外的標籤,輸入標籤的內容焦點鍵盤焦點就會移過去了
參考:
https://github.com/acejump/AceJump
若有謬誤,煩請告知,新手發帖請多包涵
Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET