54

Any way to do this kind of selection using only the keyboard?

enter image description here

With the regular Visual Studio I would use Shift + Alt + Arrows to get these columns selected. Unfortunately it doesn't work in VSCode.

Morteza Asadi
  • 1,819
  • 2
  • 22
  • 39
André Luiz Carletti
  • 1,079
  • 2
  • 9
  • 10

10 Answers10

59

By default, this is Ctrl + Shift + Alt + Arrow.

If you would like to rebind it to align with Visual Studio, put this in your keybindings.json:

{
    "key": "shift+alt+down",
    "command": "cursorColumnSelectDown",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+left",
    "command": "cursorColumnSelectLeft",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+pagedown",
    "command": "cursorColumnSelectPageDown",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+pageup",
    "command": "cursorColumnSelectPageUp",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+right",
    "command": "cursorColumnSelectRight",
    "when": "editorTextFocus"
},
{
    "key": "shift+alt+up",
    "command": "cursorColumnSelectUp",
    "when": "editorTextFocus"
}

This will conflict with the default functions of that duplicating a line or growing/shrinking with smart select, so you can add this to swap those to require Control:

,
{
    "key": "ctrl+shift+alt+down",
    "command": "editor.action.copyLinesDownAction",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+shift+alt+up",
    "command": "editor.action.copyLinesUpAction",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+shift+alt+right",
    "command": "editor.action.smartSelect.grow",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+shift+alt+left",
    "command": "editor.action.smartSelect.shrink",
    "when": "editorTextFocus"
}
Ullallulloo
  • 1,105
  • 4
  • 16
  • 31
10

You can see your current keyboard shortcuts using the menu "File" -> "Preferences" -> "Keyboard Shortcuts". And then search by "cursorColum"enter image description here

rresino
  • 1,617
  • 1
  • 11
  • 8
7

Here's what just worked for me with vscode:

Version: 1.39.2 (user setup)
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:35:18.241Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362
  1. place cursor at upper left of block to select
  2. hold down ctrl-alt-shift
  3. press down-arrow however many times you want
  4. press right-arrow however many times you want

When step 3 was to press right-arrow it didn't work for me.

5

You can do column selection several ways,

  • As you've noted, Place cursor to the start (left) of first word of first column press and hold Alt + Shift followed by Right Arrow to select top row (Try Ctrl + Shift if previous key combination is not working). With the keys pressed proceed with selecting the column by pressing Down Arrow key.

  • Place cursor to the start (left) of first word of first column Press and hold Alt + Shift and repeatedly press Down Arrow to add more cursors. (Some versions of VSCode also use Ctrl+Shift instead) Once cursors added select the words by a simple Shift + Right Arrow

  • Ctrl+D selects next occurrence of the word currently under cursor.

  • Ctrl+Shift+L selects all occurrences of word currently selected under cursor, regardless of if those words are above of below the cursor.

Abdullah Leghari
  • 2,332
  • 3
  • 24
  • 40
3

It needs to install Visual Studio Keymap:

  1. Open View -> Extensions (or Ctrl + Shift + X)
  2. Search for visual studio keymap
  3. Install it & restart VSCode

Now column selection available by Shift + Alt + Arrows.

vladimir
  • 13,428
  • 2
  • 44
  • 70
1

I had to do the following:

  1. Open Keybind settings: ctrl+k,ctrl+s.
  2. Remove keybindings for Notebook: Copy Cell <Up/Down> and Copy Line <Up/Down>.
  3. Search keybindings for cursorColumnSelect <Up/Down>.
  4. Reassign the bindings that say When: textInputFocus to Shift+Alt+<arrow keys>.
krkc
  • 21
  • 2
1

Default keybinding in VSC...

CMDALTSHIFTARROW (Mac)

CTRLALTSHIFTARROW (PC?)

This answer is for those who appreciate default keyboard shortcuts. I prefer them because they work (out of the box) when I use other machines and when starting up on a new Mac.

Shanimal
  • 11,517
  • 7
  • 63
  • 76
0

See Column selection like Visual Studio and https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_43.md#column-selection-mode

Column selection mode may be coming in v1.43 or soon, see demo in link above. It will be an option in the Selection menu.

Works best with mouse but key shortcuts possible too:

While this is checked, selecting with the mouse will create a column selection and Shift+arrow keys and Shift+Page Up/Down keys will also create column selection.

Mark
  • 143,421
  • 24
  • 428
  • 436
0

Sublime text has this shortcut to select columns: Ctrl + Alt + Up or Ctrl + Alt + Down.

So with adding this extension to VSCode: Sublime Text Keymap and Settings Importer.

You can just use the shortcut and done!.

0

I developed an extension that lets you create cursors and selections, wherever you want in the document, with the keyboard. It works by simply placing inactive cursors and selections, and then activate them on demand.

And I think this may be a simple way to do what was asked: https://marketplace.visualstudio.com/items?itemName=srares13.kcs

srares13
  • 1
  • 1
  • 1
    [/help/promotion](/help/promotion) – starball Jul 28 '23 at 20:44
  • Previously in my answer, I merely posted a link to my extension. I was thinking that the extension's page is self explanatory in providing both the answer and how it works, but I should have also described my answer, appropriately, in words. In addition, I didn’t post my extension, as an answer, anywhere else where it wouldn’t constitute a viable answer or solve the problem the OP has. With these being said, my answer may have been considered a spam, hence the downvote. Sorry for any inconvenience. I edited the answer, and I hope I remediated the issue. – srares13 Jul 29 '23 at 07:06
  • 1
    there's not really a need for an extension here anyway. VS Code has functionality built in for what this question is asking for. – starball Jul 29 '23 at 07:09