vim 區塊操作
2019-06-01
假設現在下面有一筆資料如下,有什麼方法把一個區塊 (數列或數行)刪除?

CTRL+v 進入視覺化區塊處理
在VIM介面中,按下CTRL+v 則會進入視覺化區塊介面,下方會顯示 「VISUAL BLOCK」,代表已經進入視覺化區塊介面。
接下來移動方向鍵,即可選取區塊。

接下來只要按下 「d」即可刪除整個選取的區塊。
刪除完資料後,則下一步則是進行補上資料,假如我們想要對以下資料前面都補上相同的符號呢? 例如前面都補上「mv」?

同樣的,我們先輸入「CTRL+v」 進入視覺化區塊介面,選取要插入的區塊,如下圖。

接著進行插入動作:
輸入大寫I
輸入插入內容
按 ESC
完成 「輸入大寫I」與「輸入插入內容」兩個動作後,僅會改變一行,如下圖

最後按上「ESC」鍵,則會全部改完,如下圖

這在做批次檔案處理時很方便,不需要寫複雜的Shell檔,就可以做簡單的批次處理。類似如下的shell檔。
