Sublime text 3. How to edit multiple lines?
Solution 1
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
Solution 2
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.
Solution 3
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.
Related videos on Youtube
Lory
Updated on May 14, 2021Comments
-
Lory about 3 years
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?
-
pwagner almost 8 yearsI'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.
-
-
J86 over 7 yearsawesome, thank you!
-
Vadim about 7 yearsfor MacOS users press CMD+SHIFT+L
-
sigurdb over 6 yearsThis 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 youtu.be/EzKS2UhZ76w?t=44s
-
Matúš Zábojník about 6 yearsHolding the ALT and clicking works as long as you have previously selected some text. You can only click within the selected text.
-
Maverickgugu over 5 yearsOn 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)
-
Oñay M. Sheard over 5 yearsAwesome, just what I needed. Thank you.
-
Ari about 5 yearsI 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 pressHOME
after that. -
callmebob about 5 years@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.
-
Ari about 5 years@callmebob guess the red arrow and the example image is moot. 👍
-
callmebob about 5 years@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?
-
a.t. almost 5 yearsSo the complete sequence could/would be:
Ctrl+F
><your search term>
>repeatCtrl+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 (withCtrl+D
) selected line. -
a.t. almost 5 yearsNote, 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 pressingCtrl+D
once you encounter the lines/occurrences you want to skip and pressEsc
. -
Bill Zito over 4 yearsThis can be done faster with the accepted answer (ctrl + shift + up arrow for Mac, ctrl + alt + up arrow for Windows and Linux)
-
Bill Zito over 4 yearsAs 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)
-
Marecky about 4 yearsI 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
-
Abduhafiz almost 4 yearsFor macOS
Cmd+D