2

vim seems to treat whitespace differently when using cw (change word) and dw (delete word).

For instance with the example text below, if the cursor is over the letter a and I type dw, it will remove the remainder of the word and the space after, while if I use cw, it dosen't delete the white space (and leaves you in insert mode as expected).

Example:

example text

This behavior is confusing as I would have thought the w (word) motion would be the same regardless of the d (delete) or c (change) verb.

2

This is how it is and this is how it is documented. If you want cw to behave like dw you can always say

:map cw dwi

See :help cw for details. Also look at w in :help cpoptions.

From the help section for cw:

Special case: When the cursor is in a word, "cw" and "cW" do not include the white space after a word, they only change up to the end of the word. This is because Vim interprets "cw" as change-word, and a word does not include the following white space.

If you prefer "cw" to include the space after a word, use this mapping:

:map cw dwi

Or use "caw" (see "aw").

  • 1
    Thanks, forgot how good the help in vim is. – rusty shackleford May 25 '18 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.