Home Download Buy Blog Forum Support

Copy matching lines

Copy matching lines

Postby cmulcahy on Tue Jun 12, 2012 1:01 pm

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
cmulcahy
 
Posts: 4
Joined: Sun Jan 23, 2011 7:41 pm

Re: Copy matching lines

Postby jbjornson on Tue Jun 12, 2012 1:34 pm

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.
jbjornson
 
Posts: 335
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Copy matching lines

Postby guillermooo on Tue Jun 12, 2012 10:52 pm

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

1) https://github.com/SublimeText/UberSelection
2) https://github.com/SublimeText/VintageEx

Example for (1)

Code: Select all
V/<regex1>/;-V/<regex2>/


("Select all lines where regex1 matches and regex2 doesn't match.")

Examples for (2)

Code: Select all
: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.")

Code: Select all
:g!/<regex>/p#l


("Select all lines where regex does not match, etc.")
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests

cron