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

How do I delete a word under the cursor?

Answer

diw

Explanation

The diw command deletes the inner word under the cursor. This is one of Vim's text object commands, where d is the delete operator and iw is the "inner word" text object.

How it works

  • d triggers the delete operator
  • iw selects the inner word (the word under the cursor, excluding surrounding whitespace)

Example

Given the text:

The quick brown fox

With the cursor on quick, pressing diw results in:

The  brown fox

The word is removed but the surrounding spaces remain. Compare with daw ("a word"), which also removes one adjacent space.

Tips

  • Use ciw to delete the word and enter insert mode in one step
  • Use yiw to yank (copy) the word without deleting
  • Works with any operator: gUiw to uppercase, guiw to lowercase

Next

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