Sublime text 3. How to edit multiple lines?

192,144

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.

Share:
192,144

Related videos on Youtube

Lory
Author by

Lory

Updated on May 14, 2021

Comments

  • Lory
    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
      pwagner almost 8 years
      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.
  • J86
    J86 over 7 years
    awesome, thank you!
  • Vadim
    Vadim about 7 years
    for MacOS users press CMD+SHIFT+L
  • sigurdb
    sigurdb over 6 years
    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 youtu.be/EzKS2UhZ76w?t=44s
  • Matúš Zábojník
    Matúš Zábojník about 6 years
    Holding the ALT and clicking works as long as you have previously selected some text. You can only click within the selected text.
  • Maverickgugu
    Maverickgugu over 5 years
    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)
  • Oñay M. Sheard
    Oñay M. Sheard over 5 years
    Awesome, just what I needed. Thank you.
  • Ari
    Ari about 5 years
    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.
  • callmebob
    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
    Ari about 5 years
    @callmebob guess the red arrow and the example image is moot. 👍
  • callmebob
    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.
    a.t. almost 5 years
    So the complete sequence could/would be: Ctrl+F><your search term>>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.
    a.t. almost 5 years
    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.
  • Bill Zito
    Bill Zito over 4 years
    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
    Bill Zito over 4 years
    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)
  • Marecky
    Marecky about 4 years
    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
  • Abduhafiz
    Abduhafiz almost 4 years
    For macOS Cmd+D