Support vim-exchange plugin
Is your feature request related to a problem? Please describe. vim-exchange solves the problem of swapping two regions of text and having it be undone with a single undo https://github.com/tommcdo/vim-exchange
Describe the solution you'd like Support vim-exchange Mappings https://github.com/tommcdo/vim-exchange#mappings
Additional context http://vimcasts.org/episodes/swapping-two-regions-of-text-with-exchange-vim/
Thanks for consideration
Big 👍 from me on this one. I use vim-exchange every day. The binding I use most frequently is cx<movement>. If I want to exchange two words I just move the cursor to the first word, hit cxiw, and then move the cursor to the second word, and hit . (repeat). The words now change places and can be undone with one u. Depending on the situation I'll use multiple movements, but in most circumstances repeating with . is sufficient.
I have a proof of concept of this working. It has cool properties:
- single undo
- works with dot, so can do "cxiw move cursor ." to exchange two words
Questions @ users:
- do you prefer it to work with "cx"?
- or is overwriting the current "gx" an option?
Two questions @J-Fields :
- I need "keyspace" for this operation.
- I can provide this "internally" under "gz" and users would need to "nnoremap cx gz". Ok?
- How would one do the linewise thing, that cxx works? There has to be some magic that "cc", "dd" etc. work. I could not find that in the code.
The thing is: I cant write an operator with keys = [c x].
I would definitely prefer cx if that's at all possible.
It will be possible. You would just need to create two mappings: nnoremap cx gz, nnoremap cxx gzgz
I am wondering, how does the plugin do the following: Lets say I have marked my text (first call to cx) ... can I correct or reset that?
My solution could not do that right now... I would have to "overload" undo for that, raar :>
After PR #4995 gets merged it will be possible to make that operator with a key like <Plug>(Exchange) with a default remap of cx -> <Plug>(Exchange)
@berknam , how did you find this? :> Can you help me with my question? There must be some way, that "dd" or "cc" get converted to a call of Delete/Change operator with parameters ( start, end ) being the current line. I cant find how it's done.
Other than that, I think I have this working. edit: "solved", works out of the box with my new operator.
That is done through the doesRepeatedOperatorApply and runRepeat from BaseOperator. Then on executeOperator there is a check that runs the repeat version when you have more than one operator and they are the same.
@berknam Thanks, I did not look that up yet, but I will. I looked at these Plug-mappings. Cool stuff, easy to adept.
some design decisions (open for feedback):
- if selected ranges overlap, plugin does no change
- decided against overloading undo (would be possible), but a plugin should not do this (imo)
- but if you messed up your selection (first part for exchange), see 1) you can just press ".", which does a "no change" and resets the state
- decided not to move the cursor
- no multicursor support for now
Here is the branch: https://github.com/sql-koala/Vim/tree/FeatureExchangePlugin (plugin/vimExchange.ts)
@sql-koala are there any updates on this. I'm interested and I could help with testing/development if you need help.
Hi guys. Any news on this?