# vim 使用方式 是歷史悠久的純鍵盤編輯器,是用過去科技推進未來的經典例子。 ## 開始 1. 剛進入vim時,簡單來說有3個模式: * Normal mode: 預設模式,在這個模式下移動鼠標 * Visual mode: 按下 v 之後,可以選區文字 * Insert mode: 按下 i 或 c 之後,可以輸入、編輯文字 2. 在 預設模式 下: * j 往下 * k 往上 * h 往左 * l 往右 3. 還有更多常用的操作: ``` gg for goto top file G (shift+G) for goto bottom of the file Ctrl+h for goto top of the screen Ctrl+m for goto middle of the screen Ctrl+l for goto bottom of the screen ``` ## 輸入指令 1. Keybind不是與vim互動的唯一方式,commands為您提供了更多互動方式。要輸入命令,請確保您處於 Normal mode 或 Visual mode。然後按下 `:` 鍵開始鍵入command。然後command提示將顯示在螢幕底部。 2. 常用指令: ``` :q or :quit for quit the vim :w for for writing file to disk :e [your-file-path] for open file from disk :wq for writing then quit :q! force quit when you're quiting without saving file :e! force open a new file without saving edited :qa quit all edited ``` 3. 進階指令 ``` :tabnew new tab :q also works on close tab gt next tab gT backward gt gt[number] goto the #number tab ``` ## 鍵盤組合鍵 1. Vim的鍵繫結允許您進行一些組合,這是vim最強大的設計。例如: ``` [c]hange + [i]n + [w]ord = ciw which will replace all content in a word. [v]isual + [i]n + ["] = vi" which will selected all content in ". [d]elete + [i]n + [(] = di( which will delete / cut all content in paren. ``` 2. 重複組合 - 要重複命令n次,您可以將keybind與數字結合起來,例如: ``` [times][keybind] 10j go down 10 times 10x delete char 10 times but... 10jl is go down 10 lines, and go left 1 char if you want to go down and left 10 char, you should: 10j10l ``` ## 配置 vim 1. 瞭解更多關於對映細節的資訊: [Vim: Key mapping Guide](https://dev.to/mr_destructive/vim-keymapping-guide-3olb) 2. map 的使用方式: ``` {mode}{attr}map {key} {command} map {key} {command} nnoremap {key} {command} ``` 3. 撰寫 Function ``` function FunctionName() " your code here endfunction ```