tednaleid / sublime-EasyMotion

Sublime Text 2 plugin to quickly jump to any character in the visible area of the active view.
Apache License 2.0
386 stars 24 forks source link

Ability to place a new cursor instead of jump #30

Open ackerdev opened 11 years ago

ackerdev commented 11 years ago

One thing I've always desired in ST2 was the ability to place a new cursor (eg. cmd-click) arbitrarily with only the keyboard. Currently, the only way I can find is ctrl-shift-up/down, or cmd-d, but no way to do so arbitrarily. I run into situations where this would be handy often when I am trying to say, select a variable name that also occurs in, say, a string; but you don't want to select the string occurrence; cmd-d doesn't really offer any way to skip a selection.

Perhaps something like cmd-alt-;/ctrl-alt-; could be used to signify that instead of moving the cursor here, that a new cursor should be placed at that location, allowing you to place new cursors arbitrarily?

tednaleid commented 11 years ago

Interesting idea, I don't think this would be all that difficult to implement, but I'm also not sure that I use multiple cursors enough to judge it's worth. When I do use them, I tend to use them on a bunch of lines where I think it would actually be easier to use the mouse. Are there situations where you use multiple cursors on a line or two where the cost of using a mouse is more than it would be to hit a multi-key shortcut?

Are there others that would find this feature useful?

ackerdev commented 11 years ago

Generally, when I run into the need for this, I am trying to select, say, a variable name. But the variable name might be a pretty common word, or perhaps is repeated in a string or such at some point between two instances of the variable name. Here's an example in ruby:

line = @socket.readline
do_something line

So, if I'm at the first occurrence of line, and I want to rename this variable, I might try cmd-d, selecting the next occurrence of 'line', but that actually selects the second half of readline. As far as I know, there is no way in vanilla ST2 for me to properly select just both of the 'line' variables via keyboard. It's not likely that I would use this on a mass scale; ctrl-shift-↑/↓ are more effective for multiline edits, and mouse would probably still be preferred for selecting lots of lines at different locations, but I would appreciate the ability to do this quite a lot as I would no longer have to remove a hand from the keyboard to accomplish what could be a relatively simply keyboard task.

tednaleid commented 11 years ago

Ah, I do this a little differently as I'm mostly in vintage (vim) mode. I go to the start of the word (maybe with EasyMotion if I'm not already there) and type cw to change the variable name "word". Then when it's done, I'll jump to the next instance with EasyMotion and just type a . to re-do the replacement again (vim replays the last command with a . so it ends up changing the word under the cursor to the same word you'd typed previously).

I could see the potential use for what you're suggesting though, if there are others that also think it's a good idea, I'd be willing to look into implementing it.

ackerdev commented 11 years ago

Yeah, I'm not a vintage man (yet?). Though there are a few less common occurrences that it could come in handy in but basically it comes down to any time that having multiple cursors would be handy without needing to use a mouse.

I'd certainly be forever grateful if that's more incentive :)

lydell commented 11 years ago

@ackerdev About your example:

line = @socket.readline
do_something line

Let's say that the cursor is placed at the very beginning.

If you press ctrl+d, "line" (the very first word) will be selected. Press it again and the next "line" (the very last word) will be selected. The end of "readline" won't be selected.

If you, however, press shift+ctrl+right, or ve (in Vintage mode), or double-click etc., "line" (the very first word) will be selected, too. But now, when you press ctrl+d, the end of "readline" will be selected! Press it again and the next "line" (the very last word) will be selected.

So cmd+d behaves differently depending on how the first selection was done.

Now consider this example:

line = @socket.readline # See below for why we read the line this way
do_something line

This time it does not matter (except for the end of "readline" issue, of course) if you started the selection with ctrl+d; the "line" in the comment will be selected in either case. But there is a solution! When ctrl+d has selected the "line" in the comment, press ctrl+k followed by ctrl+d. That will unselect the last added selection, and move on to the next. You end up having both "line" variables (the very first and last words) selected.

So, your use case does not back up the request. Still, I'm in favor for it.

I've actually thought about this for some time. Why is there no keyboard equivalent to ctrl+click? When I read this issue, my first thought was "Yes! This is the solution!"

I use multiple cursors a lot (together with Vintage mode). Whenever I want to do so, I look for something common between every place I'd like to place a cursor, and there always are, since otherwise it wouldn't make sense to edit with multiple cursors. The common thing could be a variable name, a language construct (for, if, array, return etc.), or, in the worst case, a separator or operator (', ', ., +, //). Usually, ctrl+d does the job. But sometimes, especially when the common thing is in the last group, there might be too many occurrences of it, so even the ctrl+k, ctrl+d way gets cumbersome.

@tednaleid

Are there situations where you use multiple cursors on a line or two where the cost of using a mouse is more than it would be to hit a multi-key shortcut?

Yes, I use my computer almost entirely only with the keyboard, since using mice give me problems with the fingers operating the mouse (typing on a keyboard does not).

ackerdev commented 11 years ago

@lydell Yes, I'm aware, though it was a very simple example of the problem. Add several lines between all of this and you are starting to get a mess of selecting and deselecting. I've run across a few times where I've simply needed this on two or more places where I needed to add the same text, that may not have originally contained the identical text that would make cmd+d or even cmd-shift-↑/↓ impossible to make use of, but it's hard to come up with an example of this kind of thing on the spot.

But yes, sometimes a lot of awkward finagling around with your selection and commands can get you what you need, but the big problem is really for people who use keyboard the majority of the time suddenly having to slow down and maneuver the mouse over to ST2 and cmd+click on something.

lydell commented 11 years ago

Yes! That's exactly how I feel as well!

chinghanho commented 11 years ago

I currently use EasyMotion + SublimeMarkAndMove plugin to do this, but I wish there was a better way.

jklaiho commented 9 years ago

Old ticket, but I use multiple cursors extensively and think this would be excellent, so +1.

goerwin commented 9 years ago

+1. I see this is an old thread but the feature will come in handy for a lot of us.