VSCode column selection with keyboard

39,436

Solution 1

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"
}

Solution 2

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.

Solution 3

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.

Solution 4

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

Solution 5

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.

Share:
39,436
André Luiz Carletti
Author by

André Luiz Carletti

Software developer trying to learn something new all the time.

Updated on July 17, 2022

Comments

  • André Luiz Carletti
    André Luiz Carletti almost 2 years

    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.

  • André Luiz Carletti
    André Luiz Carletti about 7 years
    None of them worked here. I still couldn't do like on regular Visual Studio ALT + Arrows.
  • Abdullah Leghari
    Abdullah Leghari about 7 years
    @AndréLuizCarletti you probably have an older version of VSCode.
  • André Luiz Carletti
    André Luiz Carletti about 7 years
    I am using Version 1.11.2. Date 2017-04-13. Do I need any special plugin to get the shortcut working?
  • Dan Bechard
    Dan Bechard about 4 years
    This has been one of my biggest pet peeves with VS Code since I started using it. This makes it so much more usable, you da best!
  • mcoolive
    mcoolive over 2 years
    On MACOS : Command + Shift + Alt/Option + arrows.
  • Ralf Zosel
    Ralf Zosel over 2 years
    On Mac OS 'Preferences' is located in the menu "Code" instead of "File".