Column (Box) selection in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
4 min

banner

# Table of Contents

  1. Column (Box) selection in Visual Studio Code
  2. Column selection in VS Code using keyboard shortcuts
  3. Setting custom keyboard shortcuts for Column select commands
  4. Enable column selection via the top menu

# Column (Box) selection in Visual Studio Code

To select columns in Visual Studio Code:

  1. Hold Shift + Alt (Shift + Option on macOS) and drag your mouse.
  2. A separate cursor gets added to the end of each selected line.

column selection vscode

You can press and hold Shift + Alt and click on the position where the column should end.

If you use Ctrl/Cmd as your multi-cursor modifier, use the Shift + Ctrl (or Shift + Cmd on macOS) keyboard shortcuts instead.

You can set the multi-cursor modifier by:

  1. Clicking on Selection in the top menu.
  2. Selecting Switch to Ctrl+Click for Multi-Cursor or Switch to Alt+Click for Multi-Cursor.
Note that you might have to press Alt on Windows and Linux to show the top menu.

If you pick Selection -> Switch to Ctrl (or Cmd) for multi-cursor then you have to use Shift + Ctrl (or Cmd on macOS).

If you pick Selection -> Switch to Alt (or Option) for multi-cursor then you have to use Shift + Alt (or Option on macOS).

selection switch to ctrl for multi cursor

# Column selection in VS Code using keyboard shortcuts

You can also use keyboard shortcuts to select columns.

This section of the docs has a table with the keyboard shortcuts for the commands.

On Windows, the keyboard shortcuts are:

  • Ctrl + Shift + Alt + arrow keys (up, right, left, down).

On macOS, the keyboard shortcuts are:

  • Cmd + Shift + Option + arrow keys (up, right, left, down).
The commands are usually not bound on Linux by default.

The easiest way to view the keyboard shortcuts for your operating system is to:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Type cursorColumn and view the keyboard shortcuts for your operating system.

view keyboard shortcuts for column select

You can also double-click on any of the rows to change the current keyboard shortcut.

Once you specify a key combination, press Enter to confirm.

# Setting custom keyboard shortcuts for Column select commands

You can also set custom keyboard shortcuts for column-select commands in your keybindings.json file.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Click on the Open Keyboard Shortcuts (JSON) icon to the left.

open keyboard shortcuts

  1. Add the following objects to your keybindings.json file.

You can adjust the key property of the objects as you see fit.

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

column select keybindings json

Assuming you use the key bindings from the code sample, you can use shift + alt + arrow keys to select columns.

column selection custom keyboard shortcuts

If you decide to use the keyboard shortcuts from the code sample above, you might have to update your copyLines and smartSelect actions because they get overridden.

You can add the following 4 additional keyboard shortcuts to keybindings.json.

keybindings.json
{ "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" }

This is necessary because by default:

  • The Copy Line Down action is set to Shift + Alt + Down.

  • The Copy Line Up action is set to Shift + Alt + Up.

  • The Expand selection action is set to Shift + Alt + Right.

  • The Shrink selection action is set to Shift + Alt + Left.

You can view the keyboard shortcuts for all operating systems in this section of the docs.

The Key column displays the key combination for the action for your operating system.

You can hover over the key combination to view the default for other operating systems.

# Enable column selection via the top menu

You can also use the top menu to enable column selection.

Click on Selection in the top menu and then click Column Selection Mode.

Note that you might have to press Alt on Windows and Linux to show the top menu.

enable column selection top menu

Once you click on Column Selection Mode, the setting is enabled and you can select columns without using any keyboard shortcuts.

If you need to disable the setting, repeat the process.

# Enable column selection using the Command Palette

You can also use the Command Palette to enable column selection.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type column selection and select Toggle Column Selection Mode.

toggle column selection mode

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.