Paste a rectangular block in Visual Studio
Asked Answered
D

3

28

Is there a way to paste a rectangular block in Visual Studio (2017, for example)?

Enter image description here

The only way I can do it now is paste first the values, and then "surround" the values column with from left and right, like this:

Enter image description here

Diarchy answered 13/7, 2017 at 10:23 Comment(0)
A
43

If I understand your question correctly, you can hold Shift + Alt to select a block with the keyboard.

Copy the block from within Visual Studio and then use Shift + Alt again to select the column you want to paste it to. You can then paste it. The same as you would in Notepad++.

If you want to use the mouse you only need to hold the Alt key.

Copy multiline block in Visual Studio

Update for VS Code

In VS Code it seems to require the mouse. Click to the beginning of what you want to copy, press and hold Shift+Alt then click to the end of what you want to copy. Then release the keys and copy. When pasting, do the same for the column you want to insert.

Copy multiline block VS Code

Update: Works well and flexible in VS Code for Mac too

  • Copy block and paste at multi line cursor of same line height as the block — else it fails!
  • Very flexible! Pasted lines can have uniform or character length (=column width)
  • Optionally: Very easily enter a separator string while still in multi cursor mode.

Merge lines by copying block and pasting at multi line cursor of same line height - Visual Studio Code 1.72.2 on macOS 11.7 Visual Studio Code 1.72.2 on macOS 11.7

Anemia answered 13/7, 2017 at 10:55 Comment(11)
Genious ! I didn't know the Shift+Alt combination, only Alt + Selection then Ctrl+V doesn't work !Diarchy
Something that seems to be very important is that you copy the block of vertical text from inside Visual Studio. Any time i used the block of text coming from Notepad++ it would multiplex the text and change my 10 lines into 100 lines.Tolman
Broken in 2019 preview. It copies the whole block at each caret.Mauk
@Chris: See Chris Marisic's comment.Ahlgren
shift+alt conflict with Windows 10's input method shortcutFranchot
This does not work at all with VS version 1.5.3.2.Rebuttal
@Rebuttal If you mean VS Code then yes. It has a different method for multiline editing. It works for Visual Studio, though.Anemia
This feature works very well in Visual Studio Code 1.72.2 on macOS 11.7. Added instructions, highlights and a short screencast to the answer.Quackery
Note: My addition is currently waiting for approval.Quackery
this works, but (IMHO of course) its a horribly broken misfeature. when pasting the block, you have to be sure that it is a line, which means that you have to hit the right collum on the last part of the block exactly. Try that when selecting multiple pages. If you don't hit it right, it goes completely wild and a mess results.Orvah
Can paste a "blob" (previously copied rectangular area) without causing any of the text on the right to shift right? Essentially overwriting the dropped-in target region. The (PE) Personal Editor in the IBM-PC used to have this feature.Foxing
E
2

Use the Left Alt key on the keyboard + mouse to select multiple lines. Then, select the paste region in the same manner. And press Ctrl + V.

Evictee answered 13/7, 2017 at 10:53 Comment(1)
did you try it with my example? afraid will not workDiarchy
P
2

The pasted area has to have the same rows as the copied area. Not in Notepad++, yes in Visual Studio Code.

In the last one, you must look at the IDE's bottom.

Phillip answered 29/12, 2020 at 19:32 Comment(2)
Hello and welcome to SO! Please take the tour and read How to Answer. Please try to add new information over the existing answers.Broome
Visual Studio Code is not the same as Visual Studio. The question was about Visual Studio, not Visual Studio Code. In fact, Visual Studio Code is quite broken and crippled wrt. block mode compared to most advanced text editors and IDEs (despite the hype for Visual Studio Code).Oldster

© 2022 - 2024 — McMap. All rights reserved.