Sublime Forum

[SOLVED]Command to add a new cursor

#1

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.

0 Likes

#2

Where would this new cursor be?

0 Likes

#3

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 (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.

0 Likes

#4

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” ( stackoverflow.com/questions/1001 … on-windows ).

Would there be a command “select_lines” but for words (for example) ?

0 Likes

#5

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.

0 Likes

#6

Works great, solved.

Thank you very much!

0 Likes

#7

Hi, out of the box, you can set bookmarks at your cursor positions and use “Select All Bookmarks”.

0 Likes

#8

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. :smiley:

0 Likes

#9

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 elif action == "show": cursors.clear() by [code] 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()[/code].

Anyways, thanks to both of you.

0 Likes

#10

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.

0 Likes