tommcdo / vim-exchange

Easy text exchange operator for Vim
MIT License
756 stars 23 forks source link

Able to exchange two regions selected visually with multiple-cursors #45

Closed ghost closed 6 years ago

tommcdo commented 6 years ago

I don't know anything about the multiple-cursors plugin (aside from a high-level understanding of what it does). Can you describe the workflow that you're interested in?

ghost commented 6 years ago

Basically if you press ctrl-d on a word, in selects the other words visually and when press c changing them at the same time, like refactoring or in multiple lines. More data at https://github.com/terryma/vim-multiple-cursors

tommcdo commented 6 years ago

So would the desired workflow be something like this?

  1. Use multiple-cursors to select multiple occurrences of the same word
  2. Type X to mark the multiple selections for an exchange
  3. Use multiple cursors to select another set of a different word
  4. Type X to invoke the swap of all occurrences of the first word with all occurrences of the second word

Sounds pretty interesting and useful. I don't want to get your hopes up right now, as there's a lot more I need to know before I can judge whether this is feasible. My gut feeling right now is that it will be too complicated to support, and building a one-off specialized solution is probably a better bet.

I can think of a way to achieve this result with a different workflow using another plugin. Abolish.vim provides a :Subvert command (can be shortened to :S) which can help to do a pairwise swap of words. For example, you could use this:

:%S/{foo,bar}/{bar,foo}/gc

That will replace all foos with bar and all bars with foo (the c flag makes it ask for confirmation at each occurrence). It's admittedly not as easy as the workflow you're proposing, but it could fill the void for now.

Some things I need to consider:

  1. How does multiple-cursors actually execute the command?
    • Does it work for all Visual mode commands?
    • Does it apply the command to each execution serially?

To support this, I think exchange.vim would need to have a way to let the user specify whether the operation is to mark an operand for exchanging or perform the actual exchange. Right now, it uses the same operator for both.

ghost commented 6 years ago

Actually yes, but multiple-cursors is working in hybrid-X mode. I stopped to use vim-multiple-cursors and i started to use vim-visual-multi. (mg979/vim-visual-multi). Actually its much more improved, also it can uses default visual mode mappings that means it can run every map. So after pressing , it deactivates mode but cursors is stays selected already, and you can do operations on them. I dont know too much things about it. I'm not sure if it would work.

ghost commented 6 years ago

I'll request mg979 to add support for this plugin because understanding of visual multi plugin should be hard. For him much easier.