Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split selection into lines?

Tags:

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?

like image 987
Colonel Panic Avatar asked Jan 10 '19 14:01

Colonel Panic


People also ask

How do you break a long line in VSCode?

On Windows, press Alt + Z (macOS: Option ⌥ + Z ) to toggle word wrapping, or, select View > Toggle Word Wrap from VSCode Menu. Show activity on this post. For Windows, Pressing Alt+Z will break the line.

How do you select multiple lines and write?

Place your cursor somewhere in or next to the word you wish to select. Press Alt-F3 (Windows or Linux) or Command+Ctrl+G (Mac OS X) to highlight every instance of the word in the document. Type to replace the selected words with your changes.

How do you select all lines at once?

Select an entire line of text by holding down the "Shift" key and pressing "End", if you are at the beginning of the line, or "Home" if you are at the end of the line. Select an entire paragraph by placing your cursor at either the beginning or the end of that paragraph.


2 Answers

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".

like image 86
Colonel Panic Avatar answered Oct 04 '22 21:10

Colonel Panic


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.

like image 30
MarredCheese Avatar answered Oct 04 '22 21:10

MarredCheese