Last updated: Apr 6, 2024
Reading time·4 min
To select columns in Visual Studio Code:
Shift
+ Alt
(Shift
+ Option
on macOS) and drag your mouse.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:
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).
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 easiest way to view the keyboard shortcuts for your operating system is to:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.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.
You can also set custom keyboard shortcuts for column-select commands in your
keybindings.json
file.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.keybindings.json
file.You can adjust the key
property of the objects as you see fit.
{ "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" },
Assuming you use the key bindings from the code sample, you can use shift
+
alt
+ arrow keys to select columns.
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
.
{ "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.
You can also use the top menu to enable column selection.
Click on Selection in the top menu and then click Column Selection Mode.
Alt
on Windows and Linux to show the 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.
You can also use the Command Palette to enable column selection.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can learn more about the related topics by checking out the following tutorials: