426

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,906
ChiliYago
  • 5,155

11 Answers11

534

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)

tayopi
  • 5,506
  • 63
    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
  • 17
    @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 to VSCode's strange not really column select – 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), emacs, intelli-j, notepad++, slickedit, and lots more... Been using real column editing since at least brief in the late 80s. 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
  • 37
    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 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) (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? – None 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
154

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

Screenshot: enter image description here

MarkHu
  • 731
DrStrangepork
  • 1,743
  • 1
  • 11
  • 11
37

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

Calibr3
  • 471
12

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
  • 121
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.

  • 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

Steve
  • 517
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
2

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

kidbrax
  • 121
1

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.

imran3501
  • 11
  • 1
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
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!.