tommcdo/vim-exchange

Space isn't preserved when swapping words

jceb opened this issue · 1 comments

jceb commented

Hi, Thanks for the great plugin!

I have a little issue getting it to work properly. Here is what I did in a clean document:

|test1 test2

The cursor is represented by "|". I typed cxw, pressed w to move to the second word and pressed cxw again. This is what I got as a result:

test|2test1_

I would have expected something like this:

test2 |test1

This is actually the result of Vim teaching you bad habits. The behaviour of cw is inconsistent with all other uses of the motion w. Think about it: dw deletes the whitespace; pressing w on its own brings you to the beginning of the next word, not the end of the current (that's what e does). You probably want to use cxe instead, or alternatively, cxiw, which has the advantage that your cursor doesn't need to be at the beginning of the word.

If you really want cx to treat w the way c does, you can do this:

nmap cxw cxe