Reputation: 4296
I'm learning the basics on Vim and noticed an unexpected behavior with the cw
command.
For this command, I would expect the motion to select from the cursor to start of next word (exclusive) and apply the change operation. But I'm seeing instead that it only selects to the end of the current word (inclusive), identical to what ce
does.
Example: Hello world
with cursor on 'e'.
I get the following after running cw
:
Actual: H world
with cursor on first space.
Expected: Hworld
with cursor on 'w'.
Upvotes: 0
Views: 37
Reputation: 144
This is a special case. Normally if you want to change the word you also want the whitespace after it.
Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is on a non-blank. This is because "cw" is interpreted as change-word, and a word does not include the following white space. {Vi: "cw" when on a blank followed by other blanks changes only the first blank; this is probably a bug, because "dw" deletes all the blanks}
You can read more about it on the documentation for WORD
If you do want the whitespace removed you can try the caw
motion.
Hello world
^
-> caw
Hworld
^
Upvotes: 1