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

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

  • d triggers the delete operator
  • aw selects 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 daw when you want to remove a word cleanly from a sentence
  • Use diw when you want to delete the word but keep surrounding whitespace intact
  • Works with other operators: caw to change, yaw to yank
  • Use daW to delete a WORD (whitespace-delimited, including punctuation like commas or parentheses)

Next

How do I edit multiple lines at once using multiple cursors in Vim?