28

Sublime Text has a super useful command Selection / Split into Lines to split a selection so that you have multiple cursors, one at the end of each line.

Splitting the Selection into Lines

Select a block of lines, and then split it into many selections, one per line, using:

  • Windows/Linux: Ctrl+Shift+L
  • Mac: ⇧+⌘+L

How can I do this in Visual Studio Code?

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • Possible duplicate of [How do I get a cursor on every line in vscode](https://stackoverflow.com/questions/31490989/how-do-i-get-a-cursor-on-every-line-in-vscode) – Mark Jan 10 '19 at 17:10
  • Look at the duplicate Q. Do you want the lines to be still selected? Alt-shift-drag. Put a cursor of all selected lines, but not selected: Shift-Alt-I. – Mark Jan 10 '19 at 17:18

2 Answers2

43

The command is 'Add Cursors to Line Ends' (found in the command palette or the Selection menu). The default keyboard shortcut is Shift+Alt+I.


If you're familiar with Sublime Text, you may prefer Ctrl+Shift+L as a shortcut. In File / Preferences / Keyboard Shortcuts (Json):

{
    "key": "ctrl+shift+l",
    "command": "editor.action.insertCursorAtEndOfEachLineSelected",
    "when": "editorTextFocus"
},

This overrides a default keyboard shortcut, "Select all occurrences of current selection".

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
8

The built-in VS Code command Add Cursors to Line Ends adds the cursors to the end of each line's selection (not to the end of each line, despite the command's misleading name). But it also deselects everything, leaving you with just the cursors. If that works for you, go for it.

In contrast, Sublime's Split into lines gives you those same cursors but also leaves your original selection intact (but broken down into many selections). That behavior is more powerful since it lets you act on those selections or tap left to go to the beginning of each selection or tap right to go to the end of each selection.

For those who want Sublime's behavior, this extension gives it to you: Sublime Commands. The default shortcut is as expected: Ctrl+Shift+L.

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
  • Great answer. To add on, if you want to add multiple cursors while maintaining your highlight, you can highlight the first occurrence of a string and then use command+D to highlight the next occurrence. This behavior and keyboard shortcut is shared between vscode and sublime. – Matt Korostoff Nov 05 '21 at 19:47
  • To replicate the Sublime behavior in VScode, first use `ctrl/cmd`+`shift`+`L` to insert the cursor at the end of every line in a selection. Then use `ctrl/cmd`+`shift`+`←` to select the whole lines. – dmcknight Jul 07 '22 at 17:05
  • @dmcknight Yes, with some caveats. 1) You might have to press `ctrl` `shift` `←` twice if it stops at the end of the indentation the first time. 2) With your method, the first line's selection will begin at *the start of the line (or the end of the indentation)*. In contrast, with the Sublime command, the first line's selection will begin at *the start of your original selection*. – MarredCheese Jul 07 '22 at 19:58