其實vi雖然強大,但其實只要熟悉幾個命令,就能讓你順暢編輯文字文件囉!
下面我列出幾個讓你得心應手的指令:
- 移動(操控在右手): h(←) j(↓) k(↑) l(→)
Tips: 數字0移至行首。
Tips: 數字$移至行尾。 - 輸入: i(insert), a(insert after), o(insert newline)
- 刪除: x(=del鍵), X(=backspace鍵), dd(delete one line)
Tips: dd0刪除至行首。
Tips: dd$刪除至行尾。 - 複製: yy(copy one line)
- 貼上: p/P(paste in the next/previous line)
- 復原: u
- 搜尋: /(find down), ?(find up)
- :w(save), :q(quit), :wq(save then quit), ZZ(若檔案沒有更動,則不儲存離開;若檔案有過更動,則儲存後離開)
熟悉以上8個操作指令後,再進階去熟悉vi的一些共通用法就能更得心應手。下面兩個是我比較常用的:
- [數字N+指令] = N指令,如 [數字N+移動] 讓你移動N次。
- 小寫字母有向後的意味;大寫則是向前。如 x/X(x=del; X=backspace), p/P(paste in the next/previous line)。
另外如果你是Windows但又很想來Old School一下,可以參考Vim。
沒有留言:
張貼留言