8

If you delete backwards in vim, it doesn't delete the character under the cursor. What do you need to do to have it delete, say, back to the last space?

14

Just to clarify, if you are already in insert mode, CTRL-W is fast and usually what you want.

Regarding deleting the character under the cursor when deleting backwards in normal mode, this may be what you're after:

Prepare to have your mind blown:

dvb

Vim makes a distinction between inclusive and exclusive motion. v toggles the "inclusiveness" or "exclusiveness" of a motion. For an example of toggling the opposite direction (inclusive => exclusive), try it with e:

dve

See :help inclusive for an explication. Until now, you thought it was just esoteric nonsense! Didn't you? Didn't you?! (At least, my eyes glazed over whenever I used to read that section in the help... :)

Source: https://www.reddit.com/r/vim/comments/24wbuz/command_to_delete_one_full_word_backwards/chbbkfk/

So -- to combine that with deleting backwards to the last space -- you can use dvT<space>.

Granted, dvB, daW, diW, and vBd are faster and usually sufficient.

| improve this answer | |
0
dT<space>

to delete back to a space, where I've used <space> to mean the space character. Alternatively, you could use

dB

to delete back to the beginning of the current WORD, a WORD being a string of non-space characters. See

:help T
:help B
:help WORD

or more generally

:help left-right-motions
:help word-motions
:help motion.txt

In all those cases, though, Vim begins with the character to the left of the cursor.

| improve this answer | |
  • "Vim begins with..." - so xdB etc. – RedGrittyBrick Jun 22 '14 at 8:58
  • 2
    This answer seems to ignore the whole "character under the cursor" half of the question, beyond effectively stating in the last sentence that none of this answer's content helps with that. – 8bittree Nov 16 '16 at 19:26

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.