Selecting columns in Visual Studio Code

268,133

Solution 1

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)

Solution 2

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

Solution 3

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.

https://i.stack.imgur.com/x8tJN.png

Solution 4

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.

Solution 5

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

Share:
268,133

Related videos on Youtube

robjw
Author by

robjw

Updated on September 18, 2022

Comments

  • robjw
    robjw 8 months

    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.

    • Admin
      Admin about 7 years
      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.
    • Admin
      Admin about 7 years
      0.10.11 doesn't select a column of text for me. Was looking for the feature also.
    • Admin
      Admin about 7 years
      Looks like there is some work on it though. github.com/Microsoft/vscode/issues/4092
    • Admin
      Admin almost 5 years
      From April 2018 (version 1.23), we can use middle mouse button to select multiple columns. code.visualstudio.com/updates/…
    • Admin
      Admin almost 5 years
      VS Code doesn't have real column select. Compare: actual column select to VSCode's strange not really column select. Waiting for VSCode to support virtual space so actual column select can be added.
    • Admin
      Admin over 4 years
      i haven't found a solution for being able to column select by dragging instead of arrow buttons.
  • Steve
    Steve over 5 years
    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?
  • Lars Nyström
    Lars Nyström over 5 years
    For me it is Shift+Cmd and mouse. Maybe it has changed?
  • tom_mai78101
    tom_mai78101 about 5 years
    @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.
  • ThatsAMorais
    ThatsAMorais about 5 years
    On OS X I had to use Right Shift, Alt, Ctrl as Left did not work.
  • gman
    gman almost 5 years
    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
  • Franklin Yu
    Franklin Yu over 4 years
    @gman What's your reference for "actual column select"? Was it Sublime Text?
  • gman
    gman over 4 years
    @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.
  • Franklin Yu
    Franklin Yu over 4 years
    @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.
  • gman
    gman over 4 years
    Not it is not assuming indentation is all tabs. Well programmed editors can handle tabs or spaces or a mix just fine.
  • Kevin Farrugia
    Kevin Farrugia over 4 years
    Please update the answer as it is now Shift+Cmd on OSX.
  • Alex R
    Alex R over 4 years
    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..
  • Code4Days
    Code4Days over 4 years
    It has not changed. Yours is Shift+Cmd because you chose "Selection > Switch to Cmd+Click for Multi-Cursor"
  • Orangutech
    Orangutech over 4 years
    "The real answer", etc.
  • Myer
    Myer about 4 years
    @Eric I basically have defaults, haven't selected that option, and it's Shift+Cmd for me in vscode insiders 1.31 on mac 10.14
  • DrStrangepork
    DrStrangepork about 4 years
    The default is Shift+Option. If you select "Selection > Switch to Cmd+Click for Multi-Cursor", then it will change to Shift+Cmd. If you then select "Selection > Switch to Alt+Click for Multi-Cursor", then it will change back.
  • Jack
    Jack almost 4 years
    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
  • Erik P. Hansen
    Erik P. Hansen almost 4 years
    @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.
  • Jack
    Jack almost 4 years
    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.
  • Erik P. Hansen
    Erik P. Hansen almost 4 years
    @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.
  • vhs
    vhs over 3 years
    Works without any keyboard remapping on a fresh install of Catalina.
  • emem
    emem over 3 years
    On VSCode 1.4 not working as in the documentation - more like the comments above
  • christopherbalz
    christopherbalz over 3 years
  • Jay Bienvenu
    Jay Bienvenu about 3 years
    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?
  • MrWhite
    MrWhite almost 3 years
    "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. (?)
  • omostan
    omostan almost 3 years
    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.
  • Andreas
    Andreas almost 3 years
    Shift + Alt + left doesn't do anything in my VS Code 1.46.1
  • Peter Mortensen
    Peter Mortensen over 2 years
    This seems to be Apple only.
  • Peter Mortensen
    Peter Mortensen over 2 years
    @omostan: Agreed. They do not work at all.
  • Peter Mortensen
    Peter Mortensen over 2 years
    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
    Peter Mortensen over 2 years
    Perhaps it is time to update this answer to something that actually works?
  • DrStrangepork
    DrStrangepork over 2 years
    Yes, the answer says "On macOS"
  • Willem
    Willem about 2 years
    To anyone looking through these answers: this is the one that works!
  • Matt Kenefick
    Matt Kenefick about 2 years
    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
  • WestCoastProjects
    WestCoastProjects about 2 years
    None of the Keyboard shortcuts shown here work for macOS including converting Alt to Option and control to command
  • WestCoastProjects
    WestCoastProjects about 2 years
    @PeterMortensen Agreed. none of the keyboard stuff works on macOS
  • WestCoastProjects
    WestCoastProjects about 2 years
    Brilliant: this works perfectly
  • Alexis
    Alexis almost 2 years
    Is it only me or when I want to have all the cursors at the end of each line, it's impossible?
  • jciloa
    jciloa almost 2 years
    Also, Option + Click for placing multiple cursors in the text.
  • hepcat72
    hepcat72 over 1 year
    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).
  • Gabriel Staples
    Gabriel Staples over 1 year
    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.
  • Toto
    Toto over 1 year
    How is this better than accepted answer?
  • Evert Homan
    Evert Homan over 1 year
    Works for me, tested on both Mac and Windows.