Skip to content
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 cursors (again) #7257

Open
traverseda opened this issue Sep 10, 2017 · 24 comments

Comments

@traverseda
Copy link

commented Sep 10, 2017

See also #211, #3845, #299

Multiple cursors. Even though other ways of doing things may be more powerful, there are still users who'd prefer to use them.

There are some definite problems with "virtual cursors" like in vim-multiple-cursors.

Is not that easy. It also requires multiple buffers, like when you copy using (i.e.) six carets and then pastes accordingly in the six current positions.

This also means every caret can have it's own selection and context, so the solution of "virtual carets" is unfeasible because when (for example) a plugin relies on a caret-position-change-event it will break thanks to the wrongly assumption that the event did indeed happen.

~ @Ivanca

There's already been plenty of discussion on this, so let's try to keep away from "why" (because people want it, and it's useful for some things) and focus on the "how". That is, how to expand vims underlying metaphors to support multiple cursors cleanly and powerfully.

@justinmk

This comment has been minimized.

Copy link
Member

commented Sep 10, 2017

FWIW, I've been working on this. I'll be very interested in feedback once it's reasonably usable.

@justinmk justinmk added this to the 0.3 milestone Sep 10, 2017

@KillTheMule

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2017

As an alternative, might I suggest inccomand=nosplit? I've seen people judging that a viable alternative.

@traverseda

This comment has been minimized.

Copy link
Author

commented Sep 10, 2017

Awesome, glad to hear this is being worked on.

@wsdjeg

This comment has been minimized.

Copy link
Contributor

commented Sep 10, 2017

wow,I like this feature. but when multiple cursor is enable, how to deal with popupmenu?

@justinmk

This comment has been minimized.

Copy link
Member

commented Sep 11, 2017

Is there more than one way? There is a "primary" cursor; whatever choice is made there is duplicated at the other cursors.

edit: actually Sublime does have a different approach http://docs.sublimetext.info/en/latest/extensibility/completions.html#completions-with-multiple-cursors :

Sublime Text can also handle completions with multiple cursors but will only open the completion list when all cursors share the same text between the current cursor positions

Also from Sublime's docs:

Any praise about multiple selections is an understatement.

Um, sure ...

@balta2ar

This comment has been minimized.

Copy link

commented Sep 12, 2017

I don't mean to pollute the thread, just putting here my old message as a reminder about typical problems with vim-multiple-cursors to make sure different parts of knowledge are linked together (https://github.com/extr0py/oni/issues/184):

typical issues and user requests that already took place in the past. To name a few off the top of my head: mouse support, yank/paste behavior, completion support, interaction with other plugins (hooks to disable certain plugins when multiple cursors are active).

As for inccomand, it's great but after using it for a while, it felt somewhat incomplete. For examples, this: #5608

@KillTheMule

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2017

As for inccomand, it's great but after using it for a while, it felt somewhat incomplete. For examples, this: #5608

Good news then, I'm working on that as part of #7231. It already works, but kind of conflicts with the search highlighting sometimes, which will need to be solved later on.

@justinmk

This comment has been minimized.

Copy link
Member

commented Sep 12, 2017

mouse support,

@balta2ar What do you mean by "mouse support":

  • placing a cursor with the mouse ?
  • cascading mouse motions to all cursors ?
  • something else?

completion support

The only thing that makes sense to me: let the "primary cursor" operate the menu, and whatever choice is made there is duplicated at the other cursors.

interaction with other plugins (hooks to disable certain plugins when multiple cursors are active).

Like a MulticursorPre autocmd ?

@justinmk justinmk added the atoms label Sep 12, 2017

@balta2ar

This comment has been minimized.

Copy link

commented Sep 12, 2017

placing a cursor with the mouse

That's exactly what I meant. Perhaps also removing a cursor if an existing cursor was clicked. In VSCode though I remember there was a problem with conflicting keybindings (ctrl+click would follow the definition instead of placing a cursor). microsoft/vscode#3091 Not saying it's a problem in vim, just pointing out gotchas in other editors.

cascading mouse motions to all cursors

Hm, never thought of that. Like what actions? Selection?

The only thing that makes sense to me: let the "primary cursor" operate the menu, and whatever choice is made there is duplicated at the other cursors

That sounds reasonable, though the devil could be in the details. I basically wanted to point out that it's a very huge bummer that completion menu cannot be used with current implementation of https://github.com/terryma/vim-multiple-cursors, while other editors do that (like VSCode). To me, it's probably issue number one right now (along with general instability and unpredictable behavior -- if you press something beyond the plugin's prime, vim's gonna burst with errors corrupting text along the way).

Like a MulticursorPre autocmd ?

Probably yes, what I meant is this: https://github.com/terryma/vim-multiple-cursors#interactions-with-other-plugins
But again, it depends on the core implementation details. The reason why such mechanism is needed in vim-multiple-cursors is because the plugin is somewhat naive and its actions are observed by other plugins such as deoplete, neocomplete or YouCompleteMe and excessive (sometimes harmful) work is performed as a result. Maybe there are ways to implement it transparently to all the plugins, or maybe there could be a reason to expose some API, I just don't know at the moment. Maybe plugin authors have ideas about that, e.g. @Shougo or @Valloric.

As for copy/paste, two scenarios are intuitive: 1) copy "something" using one cursor, create N cursors, paste that "something" into N locations 2) create N cursors, copy something, move cursors, paste. Each cursor should paste it's own data (a part of that implemented in terryma/vim-multiple-cursors#110).

Another minor "nice-to-have"s are:

  • search for the whole next word if in Normal mode
  • search for exact text if in Visual mode (both are currently working as expected in the plugin and have an option to toggle)
  • convert search results into cursors (in a file or in a selection).
  • mappings for actions like FindNext, GoBack (undo FindNext), SkipCurrent.

Looking through https://github.com/terryma/vim-multiple-cursors/issues may give more ideas about what users expect from a multiplecursor feature and the current state of things.

@justinmk

This comment has been minimized.

Copy link
Member

commented Sep 12, 2017

Another minor "nice-to-have"s are

All the "search" behaviors can be trivially scripted by exposing some API like cursors_add(), cursors_get().

@balta2ar

This comment has been minimized.

Copy link

commented Sep 15, 2017

One more thing to keep in mind: how will multiple cursors work with plugins that extend navigation/selection capabilities or operate with text objects, e.g.:
https://github.com/terryma/vim-expand-region
https://github.com/kana/vim-textobj-user
https://github.com/wellle/targets.vim

@balta2ar

This comment has been minimized.

Copy link

commented Jan 18, 2018

Hi, @justinmk! I wonder how things are going with that PoC that you mentioned? I remember someone posting links to video recordings of a vim meetup in Berlin where you talked about your prototype and demonstrated it. That's great news indeed! Do you have any estimates or plans when it could go public? Maybe it could attract more contributors, maybe even students could offer their help as it was with the initial implementation of inccommand feature?

@justinmk

This comment has been minimized.

Copy link
Member

commented Jan 18, 2018

Soon(ish).

@andreyorst

This comment has been minimized.

Copy link

commented Mar 31, 2018

I've read #211, #3845 and just would like to add some note about multicursor usage. It can bring native snippets support into neovim. If we will be able to add multi cursors with macroses or mappings and abbreviations to certain positions from normal mode, then basically it will become a snippet engine. I'm currently using my own silly snippet engine based on abbreviations, and hideously complex macroses, and with multi cursor support I will be able to do it much easier. Take a look:

Class snippet and getter+setter snippets:
class

Main and for snippets:
main_for

And this is how getter/setter is done:
image
And for snippet with jump markers:
image
Abbreviation that triggers for apperiance and then triggers jump mapping:
image
And this is how I jump:
image
(— Andrey you could just use Ultisnips ot snipmate or even visual studio code with neovim plugin!
— No! Thats boring!)

So I developed this a while ago, and it is usable, except that i need 2 different mappings to replace single placeholder and another to replace several placeholders simultaniously, but in VS Code (I did not accidentally mentionid it above) it is done with multicursor, like so:
image
and we can jump between them. And as it is multicrusor, it will change text everywhere, so I won't need to use abbreviation hacks like double / symbol that is being placed right before cursor | in %s/\<placeholder\>|/g to achieve the same behaviour.

I know it is complex tricks if you didn't done this before, and I believe that advanced multicursor usage will make such cool stuff easier to make, and I just wanted to mention it here, because just voting for feature is not enough for me.

@mg979

This comment has been minimized.

Copy link
Contributor

commented Apr 12, 2018

What's the status on this? I'm working on a multiple cursors plugin myself and I'm pretty excited at the progress I'm making. For now it can't edit anything but still :).

Some random pics:


Place cursors at words:

Imgur


Select inside/around brackets/quotes/etc:

Imgur


Alternate cursor/extend mode, motions (even %), reverse direction (as in visual mode) and extend from the back. At any time you can switch from extend to cursor mode and viceversa.

Imgur


Indipendent anchoring

Imgur


Find words under cursor, add new words (patterns stack), navigate regions, skip them, add regions with regex(works with cursors too).

Imgur


Select all

Imgur

Still a work in progress but I'm excited. What do you say? Worth pursuing or progresses in this area have been made, that I'm not aware of?

@balta2ar

This comment has been minimized.

Copy link

commented Apr 12, 2018

@mg979 Writing such plugin is no doubt a great experience and a learning opportunity, and I love seeing your enthusiasm, but if you want to be pragmatic, I think contributing to an already existing and a very popular plugin https://github.com/terryma/vim-multiple-cursors/ could be more beneficial for the whole vim community. Have you considered that? I'm sure your skills will be very valuable there.

@andreyorst

This comment has been minimized.

Copy link

commented Apr 12, 2018

@mg979 IIUYC the last gif shows mappings needed to use your plugin. Theese are hell lot of mappings, that may conflict with other plugins. I don't know how it will be implemented in neovim, but I believe that it shold be sort of separate multi cursor mode, like normal, insert, mc_normal, mc_visual, etc. It will be more generic and will fit better in vim filosophy.

But having a plugin that may extend this modes (if it will be implemented lise so) will be good point. Something like how surround.vim adds new semantics to exisiting modes, but for multicursor mode with multicursor features.

@mg979

This comment has been minimized.

Copy link
Contributor

commented Apr 12, 2018

@balta2ar if I was satisfied with vim-multiple-cursors I wouldn't have started a new plugin. That plugin is limited in what it can do (it implements only a subset of the things you can do in other editors with multiple cursors), it's also slow and it doesn't work well with neovim in general(in my own experience). I'm sure vim can do much better than this.

@andreyorst it's true that mappings could be an issue. I'm mostly using <buffer> mappings (if one wanted, only one non-<buffer> mapping would be necessary, to start the mode), that are mapped when the visual-multi mode starts, and are unmapped when it is exited. Still, they could overwrite other <buffer> mappings and clear them on exit. It's already possible to toggle motion mappings ('w', 'b', etc) and one would use the arrow keys to move cursors/extending selections, and normal keys for the rest (à la Sublime Text, that is). No problems there.

@wsdjeg

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2018

@mg979 does this plugin host on github?

vim-multiple-cursor sometimes does not work for me. so I also implement a new plugin in spacevim.

iedit support two mode iedit-normal/iedit-insert

@mg979

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2018

@wsdjeg I put it on github here, but it can't do much for now. There are no editing functions, and bugs.

But it can do this for now.
Imgur

@balta2ar

This comment has been minimized.

Copy link

commented Apr 13, 2018

@wsdjeg I'd like to try iedit but I don't use SpaceVim. Is there a separate repo for iedit? Or what parts do I need to take out of SpaceVim into my configuration?

@andreyorst

This comment has been minimized.

Copy link

commented Jun 22, 2018

Soon(ish).

@justinmk when(ish) ';^)

Actually I've discovered kakoune and it blew my mind *
These multi-cursors are maybe the best implementation I've ever seen. Please say that we will be able to do something similar to this.

* By "blew my mind" I've actually meant that this project is really incredible, and exists already for like 7 years, and I've never heard of it anywhere, but this is what any Vim/NeoVim user must try, it is pure amazing.

@balta2ar

This comment has been minimized.

Copy link

commented Jun 22, 2018

What's also amazing is the plugin (https://github.com/mg979/vim-visual-multi) that @mg979 advertised earlier in this thread. I was a bit sceptical initially because there was no editing support back in April, but it was implemented and in practice it has exceeded my expectations. If you're using classical https://github.com/terryma/vim-multiple-cursors/ and you're not entirely satisfied with it, you got to try https://github.com/mg979/vim-visual-multi, it's a substantial step forward, thanks to @mg979.

@kurkale6ka

This comment has been minimized.

Copy link

commented Jun 22, 2018

I agree. with @andreyorst. kakoune is amazing. It has the best multi cursor implementation out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.