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
dtriggers the delete operatoriwselects 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
ciwto delete the word and enter insert mode in one step - Use
yiwto yank (copy) the word without deleting - Works with any operator:
gUiwto uppercase,guiwto lowercase