tommcdo/vim-exchange

Using 'cx' {motion} followed by 'cxx' has strange behavior

kevintraver opened this issue · 2 comments

This seems like an edge case, but using cx {motion} , followed by cxx doesn't seem to work as expected.

Example:

1 word
2 this is a sentence
3
4 

Use cxw on line 1, and then use cxx on line 2, will produce:

1 
2 this is a sentence
3 
4 word

This is just what it looks like to mix linewise and chararacterwise motions. When you try to paste linewise content (the line targeted by cxx) over a characterwise selection (the word targeted by cxw), the result is that the linewise content is still on its own line. Here's an example that illustrates it more clearly:

1 before word after
2 this is a sentence

Use cxw on word and cxx on line 2. The result:

1 before 
2 this is a sentence
3 after
4 word  

While this is probably not what you wanted, it's much easier to understand why it happened. The linewise motion defined by cxx wants to continue being its own line. If we remove before and after, we actually see the exact same behaviour that you described.


For your case, you could use matching -wise motions to achieve the result you want:

  • cxw and cx$
  • cxx and cxx

Ah, thanks for the explanation, that makes sense now. And yes, using matching -wise motions is probably a better idea.