How do I delete or change a word and its surrounding whitespace in a single operation?
Answer
aw
Explanation
Vim's around word text object (aw) selects a word plus the whitespace that surrounds it. Unlike iw (inner word, which selects only the word itself), aw includes a trailing space (or leading space if the word is at the end of a line). This makes daw the cleanest way to delete a word from a sentence — you're left with correctly spaced text, not a double space.
Inner vs Around
| Text object | Selects |
|---|---|
iw |
The word only (inner word) |
aw |
The word plus surrounding space (around word) |
iW |
The WORD only (space-delimited, inner) |
aW |
The WORD plus surrounding space (around) |
Example
Given: The quick brown fox
With cursor on quick:
diw→The brown fox(two spaces remain)daw→The brown fox(one space — clean result)
Change a word and its whitespace:
cawdeletes the word + space, puts you in Insert mode to type the replacement
In Visual mode
vawselects the word + surrounding space for any visual operation- Works with counts:
v2awselects two words with their surrounding spaces
Tips
- The
awvsiwdistinction applies to all text objects:a"includes the quote characters,i"selects only the content inside them dawis slightly smarter thanbdw(back to start then delete to end) because it handles leading/trailing whitespace correctly- Use
cawfor quick word replacement — you land in Insert mode immediately after deleting the old word :help text-objectslists all built-in text objects and theiri/avariants