411

Does Visual Studio Code support selecting columns of text?

I have not yet found this feature, so I am wondering if it is hidden somewhere. I am familiar with holding down Alt while selecting text, but Visual Studio Code does not behave this way.

Jim Fell
  • 5,836
  • 16
  • 55
  • 76
ChiliYago
  • 5,005
  • 3
  • 24
  • 22
  • 11
    It sure is. Hold down the Alt key and select a column of text. It has been there for as long as I can remember. – ChiliYago Mar 14 '16 at 18:20
  • 4
    0.10.11 doesn't select a column of text for me. Was looking for the feature also. – slestak Mar 16 '16 at 19:56
  • Looks like there is some work on it though. https://github.com/Microsoft/vscode/issues/4092 – slestak Mar 16 '16 at 20:02
  • 9
    From April 2018 (version 1.23), we can use middle mouse button to select multiple columns. https://code.visualstudio.com/updates/v1_23#_column-selection-using-middle-mouse-button –  May 28 '18 at 03:20
  • 5
    VS Code doesn't have real column select. Compare: [actual column select](https://user-images.githubusercontent.com/234804/28726659-0ada6b14-73fd-11e7-88e9-5ed239e56dcd.gif) to [VSCode's strange not really column select](https://user-images.githubusercontent.com/234804/28726699-38e15a22-73fd-11e7-8caf-2bd7973f0d04.gif). Waiting for VSCode to [support virtual space](https://github.com/Microsoft/vscode/issues/13960) so actual column select can be added. – gman Aug 15 '18 at 02:10
  • i haven't found a solution for being able to column select by dragging instead of arrow buttons. – s2t2 Oct 13 '18 at 15:32

11 Answers11

519

In Visual Studio Code version 1.0, you can now select columns by holding down Shift+Alt, then click and drag with the mouse. This can also be done using just the keyboard by holding down Ctrl+Shift+Alt and then using the arrow keys.

On latest version of vscode - 1.45.1, you can achieve same by Shift+Alt itself ( verified in May 2020)

whosecode
  • 3
  • 2
tayopi
  • 5,356
  • 1
  • 14
  • 13
  • 62
    It's really "click, shift+alt+drag". Much less convenient than VS classic's "alt+drag". Is there any way to make VS Code work exactly like VS? – Steve Feb 01 '18 at 19:59
  • 15
    @Steve `File > Preferences > Keyboard Shortcuts`. Then search for `cursorColumnSelect`, then you can modify the keyboard shortcuts. This is done on VS Code, version 1.22. Of note, `columnSelect` is what you would need to change for `Shift` + `Alt` + Drag, but right now, there's no way to register a mouse button down event in Electron. – tom_mai78101 Apr 29 '18 at 23:58
  • On OS X I had to use Right `Shift`, `Alt`, `Ctrl` as Left did not work. – ThatsAMorais May 11 '18 at 20:11
  • 18
    This not a column select by the definition of any editor that's ever had column select. VSCode doesn't put columns through virtual space making it useless since it's not actually a column. Compare [actual column select](https://user-images.githubusercontent.com/234804/28726659-0ada6b14-73fd-11e7-88e9-5ed239e56dcd.gif) to [VSCode's strange not really column select](https://user-images.githubusercontent.com/234804/28726699-38e15a22-73fd-11e7-8caf-2bd7973f0d04.gif) – gman Aug 15 '18 at 02:08
  • @gman What's your reference for "actual column select"? Was it Sublime Text? – Franklin Yu Sep 17 '18 at 20:22
  • 8
    @FranklinYu, [visual studio (not vscode)](https://i.imgur.com/KM49Xt6.gif), [emacs](https://i.imgur.com/ppgQNrZ.gif), [intelli-j](https://i.imgur.com/GbiPhEh.gif), [notepad++](https://i.imgur.com/O4lNgf7.gif), [slickedit](https://user-images.githubusercontent.com/234804/28726659-0ada6b14-73fd-11e7-88e9-5ed239e56dcd.gif), and lots more... Been using real column editing since at least [brief in the late 80s](https://en.wikipedia.org/wiki/Brief_(text_editor)). Not saying that's the first, just that's when I started using and needed the feature and find that editors that are missing it hinder me. – gman Sep 18 '18 at 05:45
  • @gman All right, Vim and Sublime Text does not do that. (That's why I was asking.) In addition, this feature is assuming that indentations are all tabs. This works most of the time, but we have to avoid some projects like Linux kernel or Git. – Franklin Yu Sep 18 '18 at 15:13
  • Not it is not assuming indentation is all tabs. Well programmed editors can handle tabs or spaces or a mix just fine. – gman Sep 18 '18 at 15:34
  • 35
    the fact that I have to google it and come here everytime I need to do this, means this shortcut is just not good enough.. – Alex R Oct 17 '18 at 09:13
  • Hoping for this: https://github.com/rkwan94/vscode-emacs/issues/16 – christopherbalz Nov 14 '19 at 02:53
  • In my instance of VSCode, the `cursorColumnSelect*` commands have a predicate `editorColumnSelection && textInputFocus`. The bindings aren't working, which leads me to believe `editorColumnSelection` is the issue. What does `editorColumnSelection` represent? – Jay Bienvenu Apr 09 '20 at 18:11
  • "On latest version of vscode - 1.45.1, you can achieve same by Shift+Alt itself ( verified in May 2020)" - Doesn't work for me in 1.46 (June 2020). In fact, [the docs](https://code.visualstudio.com/docs/editor/codebasics#_shrinkexpand-selection) state that `Shift`+`Alt`+`Left` / `Right` are for "shrink/expand selection", which is a different thing. (?) – MrWhite Jun 26 '20 at 22:34
  • `Shift` + `Alt` + `left` doesn't do anything in my VS Code 1.46.1 – Andreas Jul 08 '20 at 06:37
  • None of this works on Linux (Ubuntu 20.04 with Cinnamon). What works: first Shift + Alt + arrow key down. Then first extend the selection down with Shift + arrow key down. Followed by extending the selection horizontally with Shift + Alt + arrow key right. Details are in my blog post *[Keyboard-only use of block/column mode in different text editors (Geany, Visual Studio, UltraEdit, Notepad++, Visual Studio Code, and Vim)](https://pmortensen.eu/world2/2020/12/31/block-column-mode-in-text-editors-geany-visual-studio-ultraedit-notepad-and-visual-studio-code-and-vim/)* (also covers Windows). – Peter Mortensen Jan 01 '21 at 00:56
  • 1
    Perhaps it is time to update this answer to something that actually works? – Peter Mortensen Jan 01 '21 at 01:02
  • None of the Keyboard shortcuts shown here work for _macOS_ including converting Alt to Option and control to command – WestCoastProjects May 19 '21 at 21:23
  • @PeterMortensen Agreed. none of the keyboard stuff works on _macOS_ – WestCoastProjects May 19 '21 at 21:23
  • Is it only me or when I want to have all the cursors at the end of each line, it's impossible? – Alexis Jun 12 '21 at 00:15
  • 1
    What version of macOS are you on @WestCoastProjects? I'm on Big Sur and `click, opt-shift-click&drag` work for me. It works the exact same way as `click, opt-shift-click&drag` in Text Edit (except in text edit you can also just opt-click&drag - you don't need the superfluous click and shift). – hepcat72 Oct 13 '21 at 18:38
  • 1
    Notice that when using `Shift` + `Alt` then clicking and dragging with the mouse, **the place your cursor _starts_ really matters.** So, _begin_ by clicking on a desired starting cursor point _first_, then do the `Shift` + `Alt` + mouse-click-and-drag column-select trick. – Gabriel Staples Oct 14 '21 at 23:33
145

On macOS: Shift+Option and mouse, or Shift+Option+Cmd and arrow keys

Screenshot: enter image description here

MarkHu
  • 721
  • 1
  • 6
  • 11
DrStrangepork
  • 1,653
  • 1
  • 11
  • 11
32

For the ones who have tried to use the Alt Key + Mouse Selection, and failed. Try to Click the menu selection as follows:

Menu bar > Selection > {Click} Switch to Ctrl+Click for Multi Cursor. This will change the multi selection the with Ctrl key and mouse as well as enable to selection column selection with the Alt Key + Mouse Selection.

VS Code - Selection Menu - Switch to

Mr. Polywhirl
  • 540
  • 5
  • 11
Calibr3
  • 421
  • 4
  • 2
  • 11
    I find this answer to be the best and should be the accepted answer. I have no idea why others are given long and inadiquate answers that seem to be accepted by majority of viewers. – omostan Jul 05 '20 at 16:08
  • @omostan: Agreed. They [do not work at all](https://superuser.com/questions/1052795/selecting-columns-in-visual-studio-code/1563524#comment2461424_1087720). – Peter Mortensen Jan 01 '21 at 00:55
  • 2
    To anyone looking through these answers: this is the one that works! – Willem Mar 03 '21 at 10:35
  • Agreed. This one seems to get to the point. Maybe it was introduced in a later version, but this allows you to use "ALT+CLICK" in VS Code – Matt Kenefick Apr 03 '21 at 14:35
  • This should be the answer. – Mr. Polywhirl Aug 11 '22 at 18:46
10

I just published an extension for Visual Studio Code that converts a multi-line selection into a column selection. It mimics TextMate's Toggle Column Selection command and serves as an alternate approach to Visual Studio Code's commandoptionshift + arrow keys that I find more natural to work with.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Erik P. Hansen
  • 201
  • 2
  • 3
  • Your AutoHotKey example is missing this line at the top `SetTitleMatchMode, 2` so it accepts wildcard titles. A VSCode window shows `Filename.txt - MyFolder - Visual Studio Code` – Jack Jul 08 '19 at 06:40
  • @Jack I'm actually not familiar with how AutoHotKey works (those instructions came via a PR from someone else). But it sounds like you're saying that hotkey currently triggers in _all_ apps, not just VSCode? I wouldn't want to make the window title matching too strict, though, since I know that the info in the window title is user configurable. – Erik P. Hansen Jul 09 '19 at 14:26
  • 1
    No currently it doesn't trigger at all because it never finds the exact text `Visual Studio Code`. Need to set the title match mode to 2 so it searches that the title contains the text. – Jack Jul 09 '19 at 16:08
  • @Jack Thanks for the tip! I've updated the readme. Hopefully the instructions work now but I can't test it as I don't have access to a Windows machine these days. – Erik P. Hansen Jul 21 '19 at 15:49
9

As of Visual Studio Code 1.2, they have full column selection. See Column (box) selection

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Steve
  • 507
  • 1
  • 6
  • 11
9

As none of the existing answers mention this:

The simplest way to achieve the desired result (as of April 2018 version 1.23) is to middle click and drag.

Torantula
  • 91
  • 1
  • 1
8

For all you visual learners, there is (as of version at least version 1.55) a graphical menu way to turn it on and a even faster way to turn it off. Go to Selection \ Column Selection Mode to toggle this feature on or off. If Column Selection Mode is enabled, there is a notice in the bottom VSCode status bar (circled in red in my illustration). A quick click on this notice will turn it off.

enter image description here

wruckie
  • 300
  • 1
  • 4
  • 9
2

On a Mac, to use only the keyboard, I just had to use Cmd+Shift+Opt and then arrow keys.

kidbrax
  • 121
  • 3
0

I have tested this on Windows 10 Pro 1909 and Linux Mint 19.3 VSCode 1.45.1 on both OS's. When I was holding Shift+Alt+Mouse Click it was dragging the Window around. What might be a better explanation is this:

HOLD down LEFT mouse button anywhere in the code then press and HOLD SHIFT+ALT. With all 3 Held down drag mouse in any direction with the mouse for column select.

0

Click the somewhere at top line of the text. Select none or select some text. Hold the Shift key and click the somewhere in the following lines.

edib
  • 143
  • 1
  • 1
  • 6
0

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

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

You can use the shortcut and done!.