Sublime Forum

Copy matching lines

#1

Hi. I want to write a plugin, unless it already exists, that copies lines from the current document that match a regex into a new document.

Does such a plugin already exist? If not, I’ll see about starting my own first plugin. I’ll undoubtedly be back with questions.

Thanks

0 Likes

#2

I’m not sure this really warrants a plugin. All you need to do is a reg-ex search, click find all, press the right arrow to move the cursors to the end of the selections and then ctrl-c to copy the matching lines. Multiple selections are one of the coolest and most underrated parts of this application.

0 Likes

#3

Besides the simple method suggested by jbjornson, two existing plugins can make this a little bit easier too:

  1. github.com/SublimeText/UberSelection
  2. github.com/SublimeText/VintageEx

Example for (1)

V/<regex1>/;-V/<regex2>/

(“Select all lines where regex1 matches and regex2 doesn’t match.”)

Examples for (2)

:g/<regex>/p#l

(“Select all lines where regex matches and print them to a separate buffer along their line nr. and show all whitespace.”)

:g!/<regex>/p#l

(“Select all lines where regex does not match, etc.”)

0 Likes