Home Download Buy Blog Forum Support

[SOLVED]Command to add a new cursor

[SOLVED]Command to add a new cursor

Postby Black on Mon Mar 18, 2013 10:15 pm

Hi,
I'm looking for the command to add a new cursor (i.e. what CTRL+D does but without having any selection).
This is what CTRL+left click does, but I'd like to bind this action to a key.

Thanks.
Last edited by Black on Wed Mar 20, 2013 5:39 pm, edited 3 times in total.
Black
 
Posts: 10
Joined: Sun Jan 06, 2013 12:19 am

Re: Command to add a new cursor

Postby adzenith on Tue Mar 19, 2013 1:44 am

Where would this new cursor be?
adzenith
 
Posts: 1216
Joined: Mon Oct 19, 2009 9:12 pm

Re: Command to add a new cursor

Postby sapphirehamster on Tue Mar 19, 2013 6:01 pm

Yea, it's not entirely clear what you're asking. If you want to remove the selection, just hit the left or right arrow after doing CTRL-D.
If you just want the cursor on multiple lines, use ctrl+alt+up or down.

I wrote a simple plugin (https://github.com/ehuss/Sublime-Column-Select) that slightly changes the ctrl+alt+up/down behavior, and adds page-up/page-down/home/end and mouse clicks. I don't know if you know Python, but it's quite easy to make a plugin do whatever behavior you want.
sapphirehamster
 
Posts: 90
Joined: Sun Jul 01, 2012 11:19 pm

Re: Command to add a new cursor

Postby Black on Tue Mar 19, 2013 7:44 pm

Hi,
thanks for your replies.

What I was originally thinking of was to "leave" the cursor where he was, and to be able to move the "real" cursor while the other would remain at the same place (like going trough a line, "leave a cursor", continue to move the real cursor and write things at different places). One example would be have a cursor at the beginning of some words of a line (by doing CTRL+Right , "leave cursor", CTRL+RIGHT, CTRL+RIGHT, "leave cursor")

The shortcuts ctrl+alt+up/down weren't working for me for some reason.
I succesfully binded them using the command "select_lines" ( http://stackoverflow.com/questions/1001 ... on-windows ).

Would there be a command "select_lines" but for words (for example) ?
Black
 
Posts: 10
Joined: Sun Jan 06, 2013 12:19 am

Re: Command to add a new cursor

Postby skuroda on Wed Mar 20, 2013 1:58 am

You can do it with a plugin. I only minimally tested this (on ST3) but you can try it out (link). You will have to assign the keys yourself, but I included a sample with the appropriate commands/args. Basically you can create a binding to "save" the cursor position. Then when you are done you can show them all.

edit: Made a fix so it should work in ST2 now also.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Command to add a new cursor

Postby Black on Wed Mar 20, 2013 5:39 pm

Works great, solved.

Thank you very much!
Black
 
Posts: 10
Joined: Sun Jan 06, 2013 12:19 am

Re: [SOLVED]Command to add a new cursor

Postby planet on Thu Mar 21, 2013 9:31 am

Hi, out of the box, you can set bookmarks at your cursor positions and use "Select All Bookmarks".
planet
 
Posts: 25
Joined: Fri Feb 17, 2012 12:30 pm

Re: [SOLVED]Command to add a new cursor

Postby skuroda on Thu Mar 21, 2013 5:51 pm

planet wrote:Hi, out of the box, you can set bookmarks at your cursor positions and use "Select All Bookmarks".

Cool. I haven't used bookmarks much before, so that's good to know. The only plus for my home spun one is that it shows where the cursor was "saved." But if that doesn't matter, using bookmarks is definitely the way to go. I'm sure it's less error prone than mine. :D
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: [SOLVED]Command to add a new cursor

Postby Black on Thu Mar 21, 2013 10:06 pm

Hi,
I didn't know about bookmarks, thanks.

I'll still continue to use skuroda's plugin for three small reasons:
-By default, you can only see the lines on which there are bookmarks, and not the column.
-I find it more natural to "leave cursors", move the cursor to the last place, and write from there. What happens with bookmarks is that the "not saved" cursor is deleted.
-If you accidently pressed "Select All Bookmarks" (which I would have binded to a "faster shortcut") without any saved bookmarks, the cursor would be deleted, and you would have to move your hand to the mouse and click to create a new cursor.

The two last "issues" were actually initially present in the plugin too, but fixing simply required changing
Code: Select all
elif action == "show":
cursors.clear()
by
Code: Select all
  elif action == "show" and len(self.saved_cursors_map[view_id]) > 0:
            for cursor in cursors:
                self.saved_cursors_map[view_id].add(cursor.begin())

            cursors.clear()
.

Anyways, thanks to both of you.
Black
 
Posts: 10
Joined: Sun Jan 06, 2013 12:19 am

Re: [SOLVED]Command to add a new cursor

Postby skuroda on Thu Mar 21, 2013 10:11 pm

Hmm good catch on the "show" when empty. I had gone back and forth about using the current cursors, guess I should have gone the other way. You don't have to add the regions to the saved set though. Since they already exist as part of the cursor, you don't have to readd them. But I suppose if you have regions selected it would keep those too. Maybe that's what you are getting around. Either way, glad it helped. Oh and if you want a bookmark like icon, to make the row clear, you can add an icon to the "add_regions" method.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 37 guests