52

Is it possible to do pasting in multiline editing (cursor |):

text1 = [|]
text2 = [|]
text3 = [|]
text4 = [|]

Assuming I have pasted the following lines:

val1
val2
val3
val4

I would like to have this result:

text1 = [val1]
text2 = [val2]
text3 = [val3]
text4 = [val4]

What actually happens is that the clipboard content is pasted four times, once for each cursor.

Something like mentioned in this answer, but instead of typing simply pasting: https://stackoverflow.com/a/30039968/1374488

belwood
  • 3,320
  • 11
  • 38
  • 45
lukas_o
  • 3,776
  • 4
  • 34
  • 50

6 Answers6

52

Use column-edit instead of the multi-line edit mode:

  1. Click the end of the source text.
  2. Shift Alt, click the beginning.
  3. Copy.
  4. Click the end of the destination text.
  5. Shift Alt, click the beginning.
  6. Paste.
Asbjørn Ulsberg
  • 8,721
  • 3
  • 45
  • 61
belwood
  • 3,320
  • 11
  • 38
  • 45
  • 9
    That's what I have tried so far. It pastes the four rows from the clipboard four times. Maybe it's wort mentioning I am using a Mac, so it is [Shift][Option] for me. – lukas_o Apr 26 '18 at 07:44
  • 2
    I too use a mac and I use the column mode editing very frequently. Hate when things like that happen. My mac's Option key has the word "alt" on it too - sorry for any confusion. Just be be clear, I used your text. I clicked after the "val4", then held down [Shift][alt] and clicked at the beginning of "val1" and copied. Then clicked after the last |, held [Shift][alt] again clicked to the left of the first | and pasted. – belwood Apr 27 '18 at 15:24
  • 1
    Worked perfectly thanks. Does exactly what the OP wanted – Cameron Forward Oct 09 '18 at 01:14
  • 42
    When using this method, double check that you're copying the same number of lines as you're selecting in the destination ("## selections" noted in the bottom right each time), otherwise it will paste the entire selection per line – TylerW Jul 05 '19 at 20:18
  • 1
    I was trying to paste a matching number of lines from another application and got the repeating paste behavior. Using this answer as a hint, I first pasted the text into VS and then followed the answer and it worked as expected. – rockariotphobia Sep 16 '21 at 14:09
  • When trying to duplicate the ends of multiple lines to the same lines, I found that the destination selection needed to have spaces. Adding spaces to the end of each line (so that each lines ended in my destination selection) allowed the paste to work as expected. If I selected beyond the length of some lines, I got the "repeating paste" behavior. – JS. May 17 '22 at 22:28
17

I had some trouble with this until I figured it out. The second selection ( where you want to paste ), must be the same length as the first selection, otherwise it pastes all items at each location ( instead of one item per row ).

Dharman
  • 30,962
  • 25
  • 85
  • 135
Eli
  • 1,670
  • 1
  • 20
  • 23
2

1-select column of data you want to copy by holding alt+shift+mouse selection box and copy it with ctrl+c

2- select the places you want to paste into with alt+mouse click(note: this helps if the lines to be pasted into are in different places)

3-paste into the selected locations with ctrl+v

mahmoud elgml
  • 161
  • 1
  • 6
1

I had to do this for hundreds of lines, mapping db columns. What I ended up doing to speed this is was creating an excel sheet with 3 columns:

COL1          COL2   COL3
text1 = [     val1   ]
text2 = [     val2   ]
text3 = [     val3   ]
text4 = [     val4   ]

And then searching and replacing tabs.

lukas_o
  • 3,776
  • 4
  • 34
  • 50
  • What happened is that after some time and probably restarting VS Code this feature started to work again. – lukas_o May 10 '18 at 12:56
1

Worked for me https://github.com/john-guo/columnpaste . Adds Column paste command.

Dzmitry Lahoda
  • 939
  • 1
  • 13
  • 34
0
  1. Hold ALT + SHIFT Keys together
  2. Select the column fields you would like
Vaseem W
  • 69
  • 1
  • 7