0

I would like to copy some text at the beginning of several lines.

What I have is:

line

111
222
333
444

And what I want is:

line

line 111
line 222
line 333
line 444

I know that I can add line at the beginning of each lines by entering VISUAL BLOCK mode and select the beginning of the lines, then pressing Shift+i, writting line and then press Esc, but I would like a way to copy in visual block mode instead of writting.

3 Answers 3

0

Once you have yanked line from visual mode, you…

  1. move the cursor to the first 1 of 111,
  2. press <C-v> to enter visual-block mode,
  3. extend the visual selection to the first 4 of 444,
  4. press I to enter insert mode,
  5. insert the content of the default register, the line you just yanked, with <C-r>",
  6. insert a space,
  7. leave insert mode with <Esc>.

enter image description here

1

and another one:

  1. yiw copy "line"
  2. jj move to "111"
  3. <C-v>} select first col
  4. I<space><space><esc> insert 2 spaces
  5. gv reselect
  6. p paste "line"

asciicast

0

In your example you not only want to copy but also to duplicate line four times.

I don't have a solution for that but if you have:

line1
line2
line3
line4

111
222
333
444

You can simply block select (Ctrl v) and yank the block

line1
line2
line3
line4

And past (P) it in front of:

111
222
333
444

It will give you:

line1 111
line2 222
line3 333
line4 444
3
  • 1
    Thank you for the answer, I knew about this solution, but indeed I only have one block line selection that I want to paste over multiple lines block selection.
    – jeirual
    Commented Mar 27 at 9:31
  • Thanks for the feedback :-) I have no other idea unfortunately :-| Commented Mar 27 at 9:45
  • 1
    You can create the initial block with yy3p
    – D. Ben Knoble
    Commented Mar 27 at 13:47

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