101

I was using Notepad++ and now I want to use the same cool features in Sublime but I don't know how. I want to edit multiple lines at the same time like this:

But I don't want to Ctrl+Click at each line for this. I want to click at first line and click at last line for one vertical line.

How I can do this?

Jack Moody
  • 1,590
  • 3
  • 21
  • 38
Lory
  • 1,429
  • 2
  • 9
  • 10
  • I'm not sure, if I understand correctly. When I click on the first line and on the last line in sublime 3, it selects the text inbetween. it does not add a cursor at the beginning of each line. When I click on each line, it select the text up until that point. Is your behaviour different? Perhaps you want to select and edit multiple occurrences of the same string via Ctrl+D. – pwagner Sep 18 '16 at 10:25

3 Answers3

214

First, select multiple lines (by dragging mouse, shift+arrow, etc.). Then, press:

CTRL+SHIFT+L

or on MAC: CMD+SHIFT+L (as per comments)

Alternatively you can select lines and go to SELECTION MENU >> SPLIT INTO LINES.

Now you can edit multiple lines, move cursors etc. for all selected lines.

DMaster
  • 603
  • 1
  • 10
  • 23
callmebob
  • 6,128
  • 5
  • 29
  • 46
  • 9
    for **MacOS** users press **CMD+SHIFT+L** – Vadim May 01 '17 at 09:15
  • 1
    This does not work for me, but holding in ALT and clicking on where the cursor is in the document works. (sublime v3, build 3143) Here is a video that shows it https://youtu.be/EzKS2UhZ76w?t=44s – sigurdb Mar 01 '18 at 12:37
  • 1
    Holding the ALT and clicking works as long as you have previously selected some text. You can only click within the selected text. – Matúš Zábojník May 29 '18 at 10:34
  • 1
    On the Mac, after CMD+SHIFT+L, you'll have to use CMD+SHIFT+LeftArrow to have it at the beginning (similar to the screenshot in the question) – Maverickgugu Oct 29 '18 at 19:32
  • 1
    I don't think this answer addresses what the question prompted. Clearly in the image the cursor is at the start of the code block. When I do `CTRL+SHIFT+L` it takes me to the end, not the beginning. To get to the beginning, I need to press `HOME` after that. – Ari May 04 '19 at 01:41
  • @Ari OP never mentions he wants the cursor in any particular position. As it happens it is at the beginning of the line on the picture. If it was on third character for example, would you argue that my (or any other method) doesn't set the cursor on third position automatically? Nonsense. – callmebob May 05 '19 at 15:07
  • @callmebob guess the red arrow and the example image is moot. – Ari May 05 '19 at 22:10
  • @Ari No, it is not. It indicates what the OP wants to achieve - which is the multiple line edit. But again, nowhere in the text OP mentions he wants the cursor to be placed at the beginning. The fact the line is in at the beginning is as relevant as the fact it is of color white. If I pasted a an example picture with pink line (lets assume my font was set to pink) would you argue that the answer doesn't make sens because OP wanted white line? – callmebob May 06 '19 at 06:50
  • This can be done faster with the accepted answer (ctrl + shift + up arrow for Mac, ctrl + alt + up arrow for Windows and Linux) – Bill Zito Oct 24 '19 at 14:49
  • I know why I always forget how to do it. Because one has to select multiple lines first. The "split into lines" options seems logical. I really prefer WebStorm way of doing it. And for Linux the shortcut is Alt+Shift+Up/Down – Marecky Apr 02 '20 at 11:51
27

Use CTRL+D at each line and it will find the matching words and select them then you can use multiple cursors.

You can also use find to find all the occurrences and then it would be multiple cursors too.

Akar
  • 5,075
  • 2
  • 25
  • 39
  • 1
    So the complete sequence could/would be: `Ctrl+F`>``>repeat `Ctrl+D` untill all the lines you want to simultaneously edit, are selected>`esc` to escape the search bar. This leaves the cursor at the end of the search term of every (with `Ctrl+D`) selected line. – a.t. Aug 05 '19 at 14:03
  • 1
    Note, if you want to leave out a sequence of search occurrences/lines, you can set the cursor below that sequence, it will start selecting with `Ctrl+D` down to the bottom, starting back at the top, just stop pressing `Ctrl+D` once you encounter the lines/occurrences you want to skip and press `Esc`. – a.t. Aug 05 '19 at 14:04
  • For macOS `Cmd+D` – Abduhafiz Aug 25 '20 at 06:14
24

Thank you for all answers! I found it! It calls "Column selection (for Sublime)" and "Column Mode Editing (for Notepad++)" https://www.sublimetext.com/docs/3/column_selection.html

callmebob
  • 6,128
  • 5
  • 29
  • 46
Lory
  • 1,429
  • 2
  • 9
  • 10
  • 3
    As links can change, it would be helpful to add the commands from the link (ctrl + shift + up arrow for Mac, ctrl + alt + up arrow for Windows and Linux) – Bill Zito Oct 24 '19 at 14:50
  • On windows, selecting just characters in multiple rows I used: Right Mouse Button + Shift. Worked like a charm, but took a while to figure it out from this full post. – Nick N Jul 21 '22 at 15:32