Vim: insert the same characters across multiple lines

后端 未结 12 1900
慢半拍i
慢半拍i 2020-11-29 14:23

Sometimes I want to edit a certain visual block of text across multiple lines.

For example, I would take a text that looks like this:

name
comment
ph         


        
12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 14:51

    1. Move the cursor to the n in name.
    2. Enter visual block mode (Ctrlv).
    3. Press j three times (or 3j).
    4. Press I (capital i).
    5. Type in vendor_. Note: It will only update the screen in the first line - until Esc is pressed (6.), at which point all lines will be updated.
    6. Press Esc.

    mini-screencast demonstrating the method

    An uppercase I must be used rather than a lowercase i, because the lowercase i is interpreted as the start of a text object, which is rather useful on its own, e.g. for selecting inside a tag block (it):

    mini-screencast showing the usefulness of the 'it' text object

提交回复
热议问题