149

I heard Microsoft released a new editor called Visual Studio Code and it looks pretty good. One key feature that I need is multi-line edit and I can't seem to find anything about it having it.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
t tran
  • 1,575
  • 2
  • 11
  • 15
  • Related post [here](https://stackoverflow.com/q/29953479/465053). – RBT Oct 21 '17 at 03:05
  • 2
    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 – Ahmad Ismail May 28 '18 at 03:20
  • Related solution here https://stackoverflow.com/a/55580788/585398 – suraj_fale Apr 08 '19 at 19:51

5 Answers5

355

Box Selecting

Windows & Linux: Shift + Alt + 'Mouse Left Button'

macOS: Shift + option + 'Click'

Esc to exit selection.

MacOS: Shift + Alt/Option + Command + 'arrow key'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 13
    Is there any way to change this shortcut? I can't find the related entry in the key bindings. – GuiSim Nov 03 '16 at 16:17
  • Here I am having a box selection issue. I can select a box, but pasting does not work for me, I tried Command + V and a few variations, but I just get a usual paste and never a box-paste. – Michel Jan 02 '17 at 06:48
  • Probably issue is related to your environment, i can only recommend to reinstall vscode as i don't have information about configurations. –  Jan 03 '17 at 20:44
  • Who the hell, just down voted this answer while I was reading and gonna + 1 this.... ~_~ – Abdul Rehman Jan 12 '17 at 12:49
  • to paste, use the same keys used to select, and select just a straight column (0-width), then paste. – Dev Null Apr 17 '17 at 02:24
  • This should be the accepted answer. – benihana21 Jun 29 '17 at 16:53
  • I just tested this on July 23 2017 and it seems like just holding `alt` does the trick in windows. It had some weird behavior if holding `shift` + `alt` as described above. This is what you want if your goal is simply to paste contents of the clipboard into multiple lines at once. – agm1984 Jul 24 '17 at 04:08
  • This is correct answer – onmyway133 Aug 08 '17 at 12:26
  • shift+option+click doesn't work on my macbook. any idea how to resolve this? – monodev Dec 27 '17 at 16:43
  • check your settings `cmd+,` and keyboard bindings `cmd+k s` –  Dec 27 '17 at 17:16
  • 4
    This just creates a selection _from_ the current cursor, _to_ where you click. What if you wanna just "drag a square" to create one, ala Sublime (middle-click mouse + drag) or VS (alt + drag)? – Alex McMillan Mar 09 '18 at 02:13
  • the original answer was with cmd and not with shift i don’t know why someone changed this, actually i rejected this change –  Mar 09 '18 at 07:06
  • @HovhannesSanoyan Shouldn't it be _Shift + Alt + 'Mouse Left Button'_ for Windows? That's the default for me anyway and I just installed Code yesterday – Boregore Mar 16 '18 at 07:32
  • 1
    @AlexMcMillan You can start dragging from where you want the selection to start **before** you hold down _Shift + Alt_ down to create a block selection as you describe it :) – Boregore Mar 16 '18 at 07:38
  • rollback of correct, original answer –  Mar 16 '18 at 14:13
  • @Boregore that's better, but still not what I'm after. Try grabbing the last few chars of several lines, which have shorter lines between them... you *have* to be careful about where you start - it's got a very "terminal" feel to it, as opposed to the "whiteboard" feel of eg Sublime. – Alex McMillan Mar 20 '18 at 22:31
  • 2
    Fantastic. This is super useful though I don't understand why VS Code can't just be like every other major editor (on Windows) and use ALT+left mouse button to do this. Gotta be different, I suppose – Nick Gotch Nov 13 '18 at 14:19
  • 3
    It's a shame, that it is not working the same as in normal Visual Studio, especially because the combination of [Shift]+[Alt] changes language settings. – gtu Jul 17 '19 at 09:08
  • when it does work its not as good as any other idea. you can't box select unless characters already exist such as spaces – Matthew Whited Mar 18 '21 at 12:48
34

Press Ctrl+Alt+Down or Ctrl+Alt+Up to insert cursors below or above.

Sahan Serasinghe
  • 1,591
  • 20
  • 33
Joe Daley
  • 45,356
  • 15
  • 65
  • 64
  • 18
    Note: Your graphics card provider might overwrite these default shortcuts. – pearpages Apr 26 '16 at 13:40
  • 4
    You may want to edit your shortcuts. Go to File > Preferences > Keyboard Shortcuts. As an example:[ { "key": "ctrl+alt+numpad2", "command": "editor.action.insertCursorBelow", "when": "editorTextFocus" },{ "key": "ctrl+alt+numpad8", "command": "editor.action.insertCursorAbove", "when": "editorTextFocus" } ] – pearpages Apr 26 '16 at 13:53
21

The shortcuts I use in Visual Studio for multiline (aka box) select are Shift + Alt + up/down/left/right

To create this in Visual Studio Code you can add these keybindings to the keybindings.json file (menu FilePreferencesKeyboard shortcuts).

{ "key": "shift+alt+down", "command": "editor.action.insertCursorBelow",
                                 "when": "editorTextFocus" },
{ "key": "shift+alt+up", "command": "editor.action.insertCursorAbove",
                                 "when": "editorTextFocus" },
{ "key": "shift+alt+right", "command": "cursorRightSelect",
                                     "when": "editorTextFocus" },
{ "key": "shift+alt+left", "command": "cursorLeftSelect",
                                     "when": "editorTextFocus" }
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jimmy Hannon
  • 729
  • 5
  • 14
  • 3
    This is good, but not great as it doesn't _quite_ act the same as box selection in other applications. e.g. If I do `shift+alt+down` 3 times and then `shift+alt+up` once, rather than undoing my last down arrow key press so that only 2 rows are selected, it adds the row above the 1st one I had selected, so I end up with 4 rows selected. Also, you need to press `Esc` to get out of the box selection mode. I wish VS Code would provide native keyboard-box-selection support, but this answer is the next best thing – deadlydog Apr 13 '18 at 18:27
13

For multiple select in Visual Studio Code, hold down the Alt key and starting clicking wherever you want to edit.

Visual Studio Code supports multiple line edit.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jalasem
  • 27,261
  • 3
  • 21
  • 29
  • 2
    I expected this to work, but it doesn't. Instead it acts like a regular mouse-click-n-drag. – jmoreno Nov 14 '19 at 16:54
  • 3
    @jmoreno I had the same issue - only Shift+Alt+Click worked, until I did this: go to Selection menu, and select Switch to Alt+Click for Multi-Cursor. – Kon Jan 07 '20 at 20:31
  • You may also want to go to Selection and choose 'Switch to Ctrl+Click' for multi-cursor selection if you find alt clicking to not work.. – Ian Smith Jan 22 '20 at 21:41
-1

On Windows it's holding down Alt while box selecting. Once you have your selection then attempt your edit.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
codemonkeyliketab
  • 320
  • 1
  • 2
  • 17