Vim: insert the same characters across multiple lines
- Move the cursor to the
n
inname
. - Enter visual block mode (Ctrlv).
- Press j three times (or 3j) to jump down by 3 lines; G (capital g) to jump to the last line
- Press
I
(capital i). - 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. - Press Esc.
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
):
Another approach is to use the . (dot
) command in combination with i.
- Move the cursor where you want to start
- Press i
- Type in the prefix you want (e.g.
vendor_
) - Press esc.
- Press j to go down a line
- Type . to repeat the last edit, automatically inserting the prefix again
- Alternate quickly between j and .
I find this technique is often faster than the visual block mode for small numbers of additions and has the added benefit that if you don't need to insert the text on every single line in a range you can easily skip them by pressing extra j's.
Note that for large number of contiguous additions, the block approach or macro will likely be superior.