--- tags: Unix-like --- # vim [TOC] ## 操作 ### 移動 Ctrl-f:後一頁 Ctrl-b:前一頁 ``` ge b w e <- <- ---> ---> This is-a line, with special/separated/words (and some more). <----- <----- --------------------> -----> gE B W E ``` ``` ^ <------------ .....This is a line with example text <----------------- ---------------> 0 $ ``` 跳到指定的字,往後搜尋 `f+<?>` ,往前搜尋 `F+<?>` ,可以用 `;` 重複動作 ``` 3fl ---------------------> fh fy ---------->---------------> To err is human. To really foul up you need a computer. <--------------------- Fh ``` ``` % <-----> if (a == (b * c) / d) <----------------> % ``` ``` | first line of a file ^ | text text text text | | text text text text | gg 7G | text text text text | | text text text text | text text text text V text text text text | text text text text | G text text text text | last line of a file V ``` ``` +---------------------------+ H --> | text sample text | | sample text | | text sample text | | sample text | M --> | text sample text | | sample text | | text sample text | | sample text | L --> | text sample text | +---------------------------+ ``` `CTRL-G` Telling where you are ``` "usr_03.txt" line 233 of 650 --35%-- col 45-52 ``` ``` +------------------+ +------------------+ | some text | | some text | | some text | | some text | | some text | | some text | | some text | zz --> | line with cursor | | some text | | some text | | some text | | some text | | line with cursor | | some text | +------------------+ +------------------+ ``` ### 搜尋 Simple search , `/` 往後搜尋, `?` 往前搜尋。 `^` 表示開頭。 `n N` 可以查找下一個或上一個。 The characters `.*[]^%/\?~$` have special meanings. If you want to use them in a search you must put a `\` in front of them. If you type "/the" it will also match "there". To only find words that end in "the" use: ``` /\<the\> ``` ``` /^The ``` The . (dot) character matches any existing character. For example, the pattern "c.m" matches a string whose first character is a c, whose second character is anything, and whose third character is m. Example: ``` We use a computer that became the cummin winter. xxx xxx xxx ``` ### 尋找取代 ``` :n1,n2s/word1/word2/g n1~n2 之間尋找取代 :1,$s/word1/word2/g 直些取代全部 :1,$s/word1/word2/gc 詢問是否要取代 ``` ### 刪除 ``` To err is human. To really foul up you need a computer. ------------------> d4w To err is human. a computer. ------------> d$ ``` ``` there is somerhing grong here rT rt rw There is something wrong here ``` ### 剪下貼上 ``` a line a line a line line 2 dd line 3 p line 3 line 3 line 2 teh th the x p ``` ## 參考資料 * [Vim: help.txt](https://vimhelp.org/) * [vim 程式編輯器 / 鳥哥的 Linux 私房菜](http://linux.vbird.org/linux_basic/0310vi.php)