tommcdo / vim-exchange

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

Exchange paragraph with last paragraph of file using cxap (no blank line at eof) #34

Closed kiryph closed 9 years ago

kiryph commented 9 years ago

Consider following text file:

First paragraph
second line of first par.

Last paragraph of file
second line of last par.

I'd like to exchange both paragraphs. I do cxap on first paragraph and . on last paragraph. But it happens nothing. It works when I add a blank line at eof.

wellle commented 9 years ago

It's probably because they intersect. Try cxip instead.

kiryph commented 9 years ago

That works. Thanks for your reply.

So I go with cxip. I am wondering: Is there a use case for cxap?

And another question: does exchange.vim only works if there is no intersection?

tommcdo commented 9 years ago

Generally, I find I only use the a variant of text objects with the d operator. There are occasionally other use cases but it's hard to come up with them on the spot.

Yes, exchange.vim only works when there is no intersection in the two regions of text. That's because it's not obvious what to do (i.e. what the user expects) in that scenario.

wellle commented 9 years ago

Actually in this case the following approach would work: Consider two overlapping regions [] and () in this example:

   ,,,,,,,,,
aaa[bbb(ccc]ddd)eee
       ^^^^^^^^^

By switching the overlapping ends we would get:

   ,,,,,
aaa[bbb]ccc(ddd)eee
           ^^^^^

Which could be exchanged as usual. In the case above this would exclude the shared blank line from both paragraph regions and exchange the inner paragraphs as expected. Not sure if there's any downside though.

tommcdo commented 9 years ago

I considered this option, and will continue to think about it.

I think Visual-block mode will present a lot of challenges -- perhaps unsolvable ones.