How do I delete a word and its surrounding whitespace?
Answer
daw
Explanation
The daw command deletes a word including one side of its surrounding whitespace. This is one of Vim's text object commands, where d is the delete operator and aw is the "a word" text object.
How it works
dtriggers the delete operatorawselects the word under the cursor plus adjacent whitespace (typically the trailing space, or the leading space if the word is at the end of a line)
Example
Given the text:
The quick brown fox
With the cursor on quick, pressing daw results in:
The brown fox
Notice that the extra space is also removed, leaving clean spacing. Compare this with diw, which would leave a double space: The brown fox.
Tips
- Use
dawwhen you want to remove a word cleanly from a sentence - Use
diwwhen you want to delete the word but keep surrounding whitespace intact - Works with other operators:
cawto change,yawto yank - Use
daWto delete a WORD (whitespace-delimited, including punctuation like commas or parentheses)