Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do Visual Studio-style rectangular selection in Visual Studio Code?

Some people who move from Visual Studio Code (VSC) to Visual Studio (VS) want to get VS to use the same key bindings as VSC, and there seems to be a way to do so.

I want to do the reverse. My main editor is VS, and there are some files that I want to edit on VSC, so I want the key bindings on VSC to behave like VS.

In particular, I'm interested in the rectangular, or multiline editing capabilities. In VS, I can Alt-Shift-Arrow to create a rectangular selection, which I find very useful:

I want to do the same in VSC. The closest I've found is the "multi-cursor" functionality, which kinda-ish sorta-ish works in a similar way:

However, there are two key differences with how VS works, which make it a bit frustrating to use:

  • The key bindings I've found are only for adding cursors. If I select too much, I can't refine my selection -- I have to start from scratch.
  • The cursors have to be in valid cursor locations. I can't add arbitrary locations to my selection like in VS. This is particularly useful when adding and removing single-line comments to a large area of code, which may include empty lines.

Is there a way to get VSC to do rectangular selection, just like VS?

like image 652
Panda Pajama Avatar asked Dec 07 '25 13:12

Panda Pajama


1 Answers

You may be able to hold the middle moues button and drag a rectangular area.

Or, move the caret to the desired anchor point for the rectangular selection, then, while holding shift+alt (windows/linux) or shift+option (macos), click the other corner of the desired rectangular selection.

See also the dedicated VS Code user docs for "Column (box) selection" and this post on superuser.com: Selecting columns in Visual Studio Code. Matt Bierner (one of the VS Code maintainers) has also made a video about the feature here.

You can also change the modifier using the editor.multiCursorModifier setting.

For keyboard-only usage, just use whatever keyboard shortcut is bound to the editor.action.insertCursorAbove and editor.action.insertCursorBelow keyboard commands to add cursors vertically, and then select horizontally with shift + arrow keys (and optionally other modifiers). To find out what keyboard shortcut you have bound to that keyboard command, search for it in the keyboard shortcut editor UI. There are other related keyboard commands, such as addCursorsAtSearchResults, editor.action.addCursorsToBottom, editor.action.insertCursorAtEndOfEachLineSelected, editor.action.addCursorsToTop.

like image 143
starball Avatar answered Dec 09 '25 17:12

starball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!