Suppose that we have the following text in normal mode (cursor is indicated by
if we use
dw, we delete
hello<Space>1 and only
world is left; if we
hello is deleted and
<Space>world is left. Have you ever wondered
dw do not delete
de will delete the
seems that the motion
w are somewhat inconsistent. It turns out that
this has something to do with the exclusivity of motions in Vim.
inclusive motion explained
Most Vim motions are either exclusive or inclusive. This nature of the motion
is best revealed when you perform an operation (including but not limited to
y) followed by these motions.
Inclusive means that the texts
between the start and end position of the cursor is used for that operation,
exclusive means that the last character near the end of current buffer
is not included in the operation.
If you know the above difference between the exclusive and inclusive motion,
you would not be surprised about the so called inconsistency between
de. The reason is that
w is an exclusive motion and
e is an inclusive
motion. Someone has asked on the Stack Exchange site on why backward delete
db can not delete the character in the cursor
That also because
b is an exclusive motion so that the last character toward
the end of the buffer is not included.
Change the exclusivity of a motion
To force an exclusive motion to be inclusive or vice versa, you can follow the
v (from Vim doc):
v When used after an operator, before the motion command: Force the operator to work characterwise, also when the motion is linewise. If the motion was linewise, it will become |exclusive|. If the motion already was characterwise, toggle inclusive/exclusive. This can be used to make an exclusive motion inclusive and an inclusive motion exclusive.
Take the case in the first paragraph for an example,
hello w (
w becomes inclusive) and
dve will delete only
e becomes exclusive). To find more detailed doc on this behaviour, read
<Space>indicates a space character. ⏎
License CC BY-NC-ND 4.0