Vim: insert the same characters across multiple lines

后端 未结 12 1904
慢半拍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:37

    Updated January 2016

    Whilst the accepted answer is a great solution, this is actually slightly fewer keystrokes, and scales better - based in principle on the accepted answer.

    1. Move the cursor to the n in name.
    2. Enter visual block mode (ctrlv).
    3. Press 3j
    4. Press I.
    5. Type in vendor_.
    6. Press esc.

    Note, this has fewer keystrokes than the accepted answer provided (compare Step 3). We just count the number of j actions to perform.

    If you have line numbers enabled (as illustrated above), and know the line number you wish to move to, then step 3 can be changed to #G where # is the wanted line number.

    In our example above, this would be 4G. However when dealing with just a few line numbers an explicit count works well.

提交回复
热议问题