Sublime Forum

Copy lines containing "xyz"

#1

Hi there, I am using sublimetext 2 and I want to copy line containing a certain string. Is there such a posibility to lines containing “xyz”
Thanks in advance, airl

1 Like

#2

These are the steps you would need to accomplish it:

  1. You could use Ctrl+D to select all “xyz” in your document or use the search function to select all of them.
  2. After that press Ctrl+L to expand all selections to the whole lines.
  3. You might need to use Shift+Left to move the cursors back to the selected lines.
  4. Copy all the lines with Ctrl+C
  5. Paste anywher Ctrl+V
0 Likes

#3

deathaxe, thanks.
I forgot to mention that I am using mac os 10.9.5. But this is not the problem i guess (I used the cmd key instead of ctrl key). So step 1. works fine. I also can a single line with cmd L completly select but when I go to the next occurance to select this line I am losing the selection from the line before. I also tried your step 3. but with no success.

0 Likes

#4

in the meantime I installed sublime text 3 – same situation.

0 Likes

#5

I think your issue is probably that you should be creating all of the selections in step 1, not trying to do it step by step:

Here I’m first selecting the text that I’m interested in, and then repeatedly pressing Ctrl+D until all instances are selected. Once that’s done I press Left once to unselect the text but leave all cursors on their respective lines, and do a copy/paste.

This works good if there are not a lot of matches in the file. If there are potentially many, you want to do it in the other way that @deathaxe mentioned, using the find panel to select all items:

Here I’m opening the find panel, entering the text to search for and pressing Find All to find all of the matches, then proceeding as above (press Left once to unselect, then copy and paste).

On MacOS you need to use different key bindings, of course. Note also that this works here because I have the copy_with_empty_selection setting set to true (which it is by default), which will make Sublime copy the entire line that the cursor is on if there’s no text selected.

If you have that setting turned off, then instead of pressing Left to unselect the text you would press the combination that extends the text to a full line first, as mentioned above.

This should work in Sublime 2 and 3, although I used 2 here since that’s what you mentioned in your question initially.

1 Like

#6

@OdatNurd, @deathaxe thank you so much. I’ve got it, yeah!

1 Like