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

How do I replace a word under the cursor?

Answer

ciw

Explanation

The ciw command deletes the inner word under the cursor and drops you into insert mode so you can type a replacement. It combines the c (change) operator with the iw (inner word) text object.

How it works

  • c triggers the change operator (delete + enter insert mode)
  • iw selects the inner word under the cursor, excluding surrounding whitespace

Example

Given the text:

The quick brown fox

With the cursor anywhere on quick, pressing ciw deletes the word and enters insert mode. Type slow to get:

The slow brown fox

Tips

  • Your cursor can be anywhere on the word — beginning, middle, or end
  • Use caw ("a word") to also consume one side of surrounding whitespace
  • Use ciW to change a WORD (whitespace-delimited, includes punctuation)
  • Pair with . to repeat the same replacement on another word

Next

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