Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Deleting a word, starting at the end of the word, leaves the last character of the word

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading