Learn Practice Daily golf Reference

How to delete a word in Vim

In Normal mode, with the cursor on the first letter of the word, press dw. From anywhere inside the word, daw deletes the whole word and the space after it.

Try it here

Edit an email draft

Three stray words. The cursor is on the start of the repeated "the": dw it. On the next line the cursor lands inside the email address, which is full of punctuation: daW takes it in one go. Then daw takes "very" from the middle.

1 of 3Delete the repeated "the" with dw
1Send the the final report by Friday.
1Ask ops-team@example.com for the numbers.
2Be very brief.
NORMALLoading the editor…1/30.0s1:10

This editor needs a keyboard. Read on, and play it at your computer.

KeysDeletes
dwfrom the cursor to the start of the next word, so the space after goes too
defrom the cursor to the end of the word; the space after stays
dawthe whole word and the space after it (or before it, at the end of a line), from anywhere in the word ("a word")
diwjust the word, from anywhere in it, leaving the spaces either side ("inner word")
dbback to the start of the word (the character under the cursor stays)
3dw / d3wthree words
dW / daWa WORD: everything up to the next space, punctuation included (ops-team@example.com)
ciwthe word, then Insert mode to type its replacement
Ctrl-w (Insert mode)the word before the cursor, without leaving Insert mode

dw or daw?

dw is an operator and a motion: delete from here to where w would jump. It only takes the whole word when the cursor is on its first letter; from the middle of a word it deletes just the end. daw uses a text object, "a word", which means the whole word wherever the cursor is in it, plus the space that separates it from the next. That makes daw the safer habit, and it also repeats well: . after daw deletes whichever word the cursor is on next.

Reach for diw when you want the gap to stay, usually because you will type something else there, and then ciw is shorter still.

Words and WORDs

For Vim, a word is a run of letters, digits and underscores, or a run of other non-blank characters, so ops-team@example.com is seven words and dw stops at each -, @ and .. A WORD (capital) is anything between spaces. Use dW or daW for addresses, paths, URLs and anything else with punctuation in it.