vimtricks.wiki Concise Vim tricks, one at a time.

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:

  • diwThe brown fox (two spaces remain)
  • dawThe brown fox (one space — clean result)

Change a word and its whitespace:

  • caw deletes the word + space, puts you in Insert mode to type the replacement

In Visual mode

  • vaw selects the word + surrounding space for any visual operation
  • Works with counts: v2aw selects two words with their surrounding spaces

Tips

  • The aw vs iw distinction applies to all text objects: a" includes the quote characters, i" selects only the content inside them
  • daw is slightly smarter than bdw (back to start then delete to end) because it handles leading/trailing whitespace correctly
  • Use caw for quick word replacement — you land in Insert mode immediately after deleting the old word
  • :help text-objects lists all built-in text objects and their i/a variants

Next

How do I run a search and replace only within a visually selected region?