Vi Cheat Sheet
References
- Get the name of the current file
:echo @% def/my.txt directory/name of file :echo expand('%:t') my.txt name of file ('tail') :echo expand('%:p') /abc/def/my.txt full path :echo expand('%:p:h') /abc/def directory containing file ('head') - 移動浮標指令
Motion
h Move left j Move down k Move up l Move right w Move to next word W Move to next blank delimited word b Move to the beginning of the word 單字字首 B Move to the beginning of blank delimted word 單字字尾 e Move to the end of the word 單字字首 E Move to the end of Blank delimited word ( Move a sentence back ) Move a sentence forward { Move a paragraph back } Move a paragraph forward 0 Move to the begining of the line $ Move to the end of the line 1G Move to the first line of the file G Move to the last line of the file nG Move to nth line of the file :n Move to nth line of the file fc Move forward to c Fc Move back to c H Move to top of screen M Move to middle of screen L Move to botton of screen % Move to associated ( ), { }, [ ] - 常用指令
指令 說明 備註 yy 複製整行文字 y$ 複製cursor後,到行尾文字 gg=G 格式化全文 一直看人在寫gg=G
還以為打gg或G都可以... 怎麼都試不出來...
原來... 真的是打gg=G 靠... 試了好久... 機車
gg - 到文章開頂端
= - apply indentation (縮排)
G - 到文章尾端 - 分頁指令
指令 說明 備註 :tabnew 開新分頁 :tabedit path/to/file 開啟舊檔 Ctrl+6 切換分頁 gt 依序切換 :tabn,:tabp 前後切換 - 快速移動
捲動螢幕
^F 往前捲動一個螢幕
^B 往後捲動一個螢幕
^D 往前捲動半個螢幕
^U 往後捲動半個螢幕
重新調整螢幕位置
z[enter] 將游標移到螢幕頂端
zz 將游標移到螢幕中心
z- 將游標移到螢幕底端
References
- vgod給程式設計師的Vim入門圖解說明
- vi與vim, O'Reilly
沒有留言:
張貼留言