-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple cursor support #5
Comments
Hey @zyedidia, if you're not currently working on this, I'd love to take a stab at implementing it |
Sure, go for it! |
@bentranter FWIW, I'm a huge fan of the PR you've started. 👍 |
@montanaflynn can you record a video of this feature to make it clear for the rest of us? |
No I'm not :). |
@techtonik here you go: |
is there any new development on this ? |
No unfortunately not. |
There has been a new development! I have implemented multiple cursors. It's currently sitting on the The bindings are "Alt-n": "SpawnMultiCursor",
"Alt-p": "RemoveMultiCursor",
"Alt-c": "RemoveAllMultiCursors",
"Alt-x": "SkipMultiCursor", I'm not sure if it's bug free yet so I haven't merged it into master. Since the only multiple cursors I have used is the Let me know if you find any bugs. |
That's great, I'll try to test it soon.
There's a pretty multi-selection/multi-cursor in sublime/atom. Basically you select something, press |
Alright that's the behavior that my implementation has but with different keybindings. I'm also open to using different default keybindings but since you can easily rebind them it doesn't really matter. |
@zyedidia in addition to the keyboard shortcuts you've implemented for it, it would also be nice to be able to Ctrl+Click a location to spawn a new cursor there. This is the behaviour in Atom. I have not tested your new branch yet, so I'm not sure if this is the case or not in your current code. |
Ok I have just added support for that (see 340cfb8 for details). If you are using macOS though you will need to rebind it to another mouse button because Ctrl-Click is used as an alternate right click. |
Issues 1-3 all boil down to the same issue which is that the cursors don't know about the line being modified so they don't move. This might require some more thought to fix because I think it means changing where cursors are stored. |
This changes the behavior of cursor movement so that all cursors are adjusted when a change is made to the buffer. Cursors don't have to be manually moved after calling Insert or Remove, those functions will move the cursor properly on their own. This should fix issues 1-3 mentioned in the multiple cursors discussion. Ref #5
Thanks for the fix. This is working pretty well now. I've found one more issue just by playing around with it. I haven't used this in production yet, just did some quick tests. So there very well may be edge cases I have not found. The remaining issue is that if you delete characters until two cursors end up occupying the same space, they get stacked and basically double input / output. The expected behaviour is that these cursors should merge (All but one are removed) |
Yup I came across that problem. I've also found some other issues (with undo and selections) so this still needs some more work. |
I have merged the pull request so multiple cursors should be in master now. If you can't build from source you'll be able to get the nightly tonight and try it out. |
@ahoarau @zyedidia I just wanted to expand a little bit on this:
Actually they (sublime and vscode, not sure about atom) do something slightly different, that I find very useful:
Moreover the match can be case sensitive or not, depending on the current configuration on the |
These multiple cursors look like a limited version of macro recording abilities. Record a macro in Far Manager and replay it dozen times looks easier than wrapping the head around this feature. |
@techtonik As a Sublime Text and Micro user, I'm not familiar with macros, but would love behavior as Luca described. Especially if, as it sounds, macros require a separate "recording" stage, which would kill the interactive, immediate feedback workflow that I'm productive with. |
@AndydeCleyre with macros I do |
@techtonik I never use the mouse to place multi cursors. Whole word matching is useful to do refactoring where you want. I personally use the exact match in this way:
I have no idea on how to use the macros in sublime, but I don't think I could be more productive with them Another very useful shortcut is the split line: select some contiguos lines, you can place a cursor in each one of them |
Ok, there is no mouse clicking, but there is a lot of cursor moving. With macros you just chain the search for the next pattern at the end of your edit. For sublime press |
I get that the macros can be useful, expecially if you are used to them from experience of vim or similar. I think that the multi cursor approach has a big advantage: you have an immediate feedback, and if you do something wrong, you can simply ctrl+z it. If you forget something in the macro, maybe beacause you didn't notice some differences in the row... You have to redo all from scratch, and you can't know that the macro is wrong until you use it. I have the feel to be much more in control of the situation if I have feedback on what I'm doing. Moreover what if I don't know in which line I want to do some changes, or they are too many? I'm under the impression that, while it can surely be done using macros, it becomes messy. With cursor you just have to identify a pattern in the line, place cursors on all the lines, and modify the lines maintaining the cursor in sync. it is easier to do that than to say it |
I use multiple cursors multiple times a day for everything from refactoring, editing json, creating new arrays, etc... in atom and previously sublime, and I've never used macros in sublime or atom. This issue is for multiple cursors, not macros. |
@lucamoschella when you recording macro you are doing edits as usual and see the feedback. When playing you see the result. |
Yeah, I meant that you get feedback from all the lines (immediately if all fit the screen). |
Macros are especially good if there are many lines or multiple places over the file that you can not see in one screen. As I said - at the beginning of a macro or at the end you can invoke find function to place cursor to the place that will be the starting position for the next macro invocation. How do you do that with cursors if content is not at the same screen? |
This is exactly what sublime and the others do in a smarter way. If you are referring to multiple files, yes cursors are local to a single file |
Queries for automated cursor placement make sense. This way the |
Like the "refactor" function of some IDE? I often use the multiple cursors to format nicely something that I copied in the clipboard. If the refactoring is supported, it's more powerful than cursors, since it accounts for scopes and name clashes. |
After using sublime and atom I can't go back to not having multiple cursor support. Any plans to introduce this into micro? Even just select all and select next would be amazing as that covers 90% of my usage.
The text was updated successfully, but these errors were encountered: