I have the following problem in Vim.
When I want to delete with db the last character doesn’t get removed.
foo bar some words cool
^ Cursor is here, now call 'db'
foo bar some words l <- result, l not deleted
But I also want to delete the ‘l’ from ‘cool’.
I could use bdw do achieve my goal, but this feels counter intuitive.
Are there better ways do achieve my goal?
>Solution :
The best way to operate on the whole current word is to use the :help iw text object, from anywhere in the word:
diw
But, if you enjoy the cognitive weight of worrying about where the cursor is and where you want it to be, you can force :help b to include the current character by injecting a v between d and b:
dvb
or, simply, use visual selection directly:
vbd
db doesn’t do what you want it to do because the motion is exclusive. From :help 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.
Linewise motions always include the start and end position.
That v, between the operator and the motion, is a way to force the motion to be inclusive. See :help forced-motion.