0

Let's say I have some text:

ipsum
ipsum dolor
ipsum dolor sit

I want to add the word "Lorem" in front of each line.

Loremipsum
Loremipsum dolor
Loremipsum dolor sit

I can do this by:

  • Entering visual block mode at the first line,
  • Going down 2 lines
  • Entering insert mode with Shift-I
  • Typing Lorem
  • Exit insert mode (with Esc)

It will indeed put "Lorem" in front of each line but only after exiting insert mode.

I would like for multiple cursors to appear, and whatever I type would appear on all three lines, not just the top one.

Is this possible with Vim or a plugin?

2
  • Other solutions: v2j:s/^/Lorem (the first bit v2j can be replaced by your favorite way to enter a range for that chunk of text), v2j:norm! ILorem , ILorem <esc>j.j., etc. :[range]normal! . is also really powerful.
    – D. Ben Knoble
    Aug 28, 2022 at 3:13
  • Possible duplicate: vi.stackexchange.com/a/4312/10604
    – D. Ben Knoble
    Aug 30, 2022 at 14:21

1 Answer 1

1

It is not possible in Vim without special customization.

The vim-visual-multi plugin offers such functionality.

For your use case once vim-visual-multi is installed.

  • Use Ctrldown to select the part of the column you want to edit (like Ctrlv + down would do in standard Vim),
  • Use i to switch to insert mode,
  • Type your text,
  • Leave insert mode Esc,
  • Leave multiple cursor mode Esc.

All the row are edited at the same time.

vim-visual-multi is actually much more capable but this cover your use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.