Why d{motion} command is not consistent with {motion} command in Vim?

de cuts everything from, and including, the character under the cursor up to, and including, the last character of the world, e is an inclusive motion.

dw cuts everything from, and including, the character under the cursor up to, and excluding, the next word, w is an exclusive motion.

The answer to your question is not in :help d (de and dw are perfectly consistent with it) but in :help e and :help w (e and w don't have to work the same because, as the doc says, one is inclusive and the other exclusive).

Always keep in mind that everything in Vim is about composability: de is not de, it's d applied to e.


An answer to your question can be found using :h exclusive:

A character motion is either inclusive or exclusive.  When inclusive, the
start and end position of the motion are included in the operation. When 
exclusive, the last character towards the end of the buffer is not
included.

You can check, using :h word-motions, which motions are inclusive (like e) and which are exclusive (like w). For using motions just to move cursor it doesn't matter but it does when using them in operator-pendig mode.

Note that this is in no way specific to Vim, those semantics were defined by original Vi.


this is because, the motion w is exclusive motion, but the e is inclusive one.

see:

:h w
:h e

and

:h exclusive

Tags:

Vim