53

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

1
  • 4
    Please feel free to share your thoughts if you downvote, thanks!
    – lukas_o
    Apr 25, 2018 at 18:08

6 Answers 6

55

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.
6
  • 10
    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, 2018 at 7: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, 2018 at 15:24
  • 1
    Worked perfectly thanks. Does exactly what the OP wanted Oct 9, 2018 at 1:14
  • 43
    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 5, 2019 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. Sep 16, 2021 at 14:09
18

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 ).

2
  • 1
    That is what Tyler said in the comments.
    – Mark
    Jul 13, 2020 at 9:17
  • 1
    Can also be a multiple of. I.e if copying 2 lines and pasting to 4 selections it will repeat the lines in sequence.
    – sam
    Apr 27, 2021 at 6:38
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

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.

1
  • What happened is that after some time and probably restarting VS Code this feature started to work again.
    – lukas_o
    May 10, 2018 at 12:56
1

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

0
  1. Hold ALT + SHIFT Keys together
  2. Select the column fields you would like

Your Answer

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

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