14

in vs code I have the following file

1
2
3

a
b
c

Now I do the following steps

  1. cut the lines a b c.
  2. select the lines 1, 2, 3 and then go into multiple cursor mode (shift, alt I).
  3. go to the end of the each number press and type a , and then do a paste.

The result is

1, a
b
c
2, a
b
c
3, a
b
c

but the result I wanted is

1, a
2, b
3, c
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

2 Answers2

22

Check out Mark's good answer as well. There have been some updates to VS Code he mentions that should be considered as well.

Using Shift+Alt+I, you need to cut the text in multiple cursor mode as well:

1Enter2Enter3EnterEnteraEnterbEnterc

Shift+

Shift+Alt+I

Shift+

Ctrl+X

, 

Ctrl+V

enter image description here

As of the 1.23.1 April update, a more convenient, middle mouse button selection can be used.

With the cursor and keyboard, Instead of cutting the lines like normal, select from the end of the cursor to the beginning while in multi-cursor mode while holding Ctrl+Shift. After cutting the text with Ctrl+X, select with multiple cursors again by holding Ctrl+Shift. Then, type ,  and paste with Ctrl+V like you described.

enter image description here

You can also use Ctrl+Alt+Shift and the direction arrows to select with multiple cursors,

keyboard demo

Namaskar
  • 2,114
  • 1
  • 15
  • 29
12

Sometime ago this functionality was apparently added. You can simply cut to your clipboard and then paste to multiple cursors - and, if there are the same number of lines on the clipboard as multiple cursors - each cursor will get one line from the clipboard.

You no longer need to be in multi-cursor mode for the cut or however you got the text onto the clipboard. Just cut it.

Demo:

multicursor paste spread

Unfortunately, the gif cut off the full command after selecting the 1,2,3,. What you then want to do is put a cursor at the end of each line of the selection. Command: Add Cursors to Line Ends Shift+Alt+I.

VSCode 1.39 added this setting:

Editor: Multi Cursor Paste

Controls pasting when the line count of the pasted text matches the cursor count.

"editor.multiCursorPaste": "spread"

that will do what you want.

There is a second option full where each cursor will get the entire clipboard text. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_39.md#new-option-for-multi-cursor-pasting. Demo of the full option:

demo of mulit-cursor paste full option

From the multi-cursor paste release notes:

New option for multi cursor pasting

In the past, when pasting multi-line text from the clipboard, VS Code would check if the clipboard text line count matches the cursor count, and if it does, it would "distribute"/"spread" each line to a cursor. This behavior is now tunable via the editor.multiCursorPaste setting, which can have the values:

spread - Each cursor pastes a line of text (default).

full - Each cursor pastes the full clipboard text.
Mark
  • 143,421
  • 24
  • 428
  • 436
  • Thanks! Any idea how to temp toggle to the other paste type? – Sebastian Thomas Jan 09 '20 at 13:48
  • You could look at the toggle extension: https://marketplace.visualstudio.com/items?itemName=rebornix.toggle – Mark Jan 09 '20 at 19:38
  • In the gif animation, after highlighting "1 2 3" the key command is [Shift]+[Ctrl]+[l], followed by [,], followed by [Ctrl]+[v] – Adrian Sep 23 '21 at 17:22
  • @Adrian I edited the answer because I see the gif didn't catch the last keystroke. It is `Shift+Alt+I`. Add cursors to the line ends of the selection. – Mark Sep 23 '21 at 19:22
  • i got this issue on today with `Version: 1.79.0-insider (Universal)` and still not working . – Yogi Arif Widodo May 05 '23 at 06:05