Home Download Buy Blog Forum Support

Is "Copy Bookmarked Lines" doable in Sublime?

Is "Copy Bookmarked Lines" doable in Sublime?

Postby ctrager on Mon Sep 26, 2011 7:55 pm

Is there a feature like Notepad++'s Copy(Cut/Paste/Delete) Bookmarked Lines? That feature lets me do a find on all lines containing "my text", marks them, and then I can copy just those marked lines into, say, a new file.
ctrager
 
Posts: 5
Joined: Mon Sep 26, 2011 7:40 pm

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby guillermooo on Mon Sep 26, 2011 8:17 pm

You probably can skip bookmarks for that in Sublime Text:

1) Perform search
2) Alt+F3
3) Dismiss search panel with Esc
4) Ctrl+L
5) Ctrl+Shift+L
6) Copy
7) Create new buffer
8) Paste

As a bonus, you can now edit those lines and paste them back into place in the previous buffer.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby ctrager on Mon Sep 26, 2011 8:43 pm

Thanks. That's part of the way there. But I want to do more searches, add more to the select before doing the copy. So, for example, with the following 4 lines, I'd like to first search on "foo" to mark or select lines 1 and 4, and then search on "bar" to mark or select line 2. Only then do I want to copy the mark or selected lines. (What I've described is doable in Notepad++ and the commercial Textpad and I depend on it)

Doable?

1 foo
2 bar
3 something else
4 foo
ctrager
 
Posts: 5
Joined: Mon Sep 26, 2011 7:40 pm

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby guillermooo on Mon Sep 26, 2011 8:51 pm

Not out of the box, but if I got it right, this is exactly what I created UberSelection for:

https://bitbucket.org/guillermooo/ubers ... n/overview

As a side note, while this plugin isn't especially hard to use, I'm sure this kind of thing can be simplified further, like a multi-step additive selection via keyboard only.

The command you would use in UberSelection would be this one:

Code: Select all
%V/foo|bar/


It's working for me now, but I might have left a couple of loose ends when I ported it from ST1.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby guillermooo on Mon Sep 26, 2011 9:04 pm

Btw, I think I've spoken too quick. This might already be doable with bookmarks.

Perform search
Bookmark all
repeat ad lib
...
Select all bookmarks
Split into lines

That should do it for your use case, I believe... UberSelection can still do more than that, though.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby guillermooo on Mon Sep 26, 2011 9:16 pm

Sublime Text is like that saying that goes along the lines of "can't see the forest of features for the forest of features" but in the good sense.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby ctrager on Mon Sep 26, 2011 9:29 pm

After select all bookmarks, instead of your "Split into lines", I do "Expand select to lines", and then copy, and it works, BUT.... the result pasted text has additional blank lines.

( This is my first hour evaluating Sublime Text 2 so I haven't quite figured out how to install your UberSelection, but if it adds vi like commands to ST2, well, I've only dabbled with vi.... )
ctrager
 
Posts: 5
Joined: Mon Sep 26, 2011 7:40 pm

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby guillermooo on Mon Sep 26, 2011 9:47 pm

Crtl+L and Ctrl+Shift+L will first expand the selection up to and including the newline char, and then shrink it to the full line except the newline char. That's become and idiom for me in Sublime Text. Doesn't that get rid of the blank lines for you?
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby guillermooo on Mon Sep 26, 2011 9:56 pm

UberSelection is heavily inspired (read: rip-off) in vi's ex mode, but it just implements a handful of standard commands (and some of them are broken IIRC). The interesting ones --to me, at least-- resemble ex commands, but they don't even share the same syntax --save for the ranges (.,$, etc).

The installation instructions are wrong because they include information valid for ST1 only... It should be a matter of dropping the .sublime-package file inside your Installed Packages folder (a sibling of Packages, which is accessible via Preferences from the main menu).

In any case, I believe bookmarks should work in this case, and they are far simpler to use.
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Is "Copy Bookmarked Lines" doable in Sublime?

Postby ctrager on Wed Sep 28, 2011 12:06 am

Thanks again, yes ctrl-l, ctrl-shift-l works. Just for future reference, below are the steps:

1 ctrl-f to find
2 enter text to find
3 alt-f3 to find all with selection
4 escape to get rid of find bar
5 ctrl-f2 to bookmark
6 go back to step one to find and bookmark again

7 alt-f2 to select all bookmarks
8 ctrl-l to expand selection to lines

To copy:
ctrl-shift-l to split selection to lines, which has the effect of trimming the line breaks
ctrl-c to copy

Or, to delete:
don't hit ctrl-shift-l
ctrl-x to delete
ctrager
 
Posts: 5
Joined: Mon Sep 26, 2011 7:40 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: danpyq and 11 guests

cron