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

What is the difference between cw and ciw when changing a word?

Answer

cw vs ciw

Explanation

The cw and ciw commands both change a word, but they behave differently depending on cursor position. Understanding the distinction is essential for precise editing and will save you from unexpected results.

How it works

  • cw changes from the cursor position to the end of the current word. If the cursor is in the middle of a word, only the portion from the cursor onward is changed.
  • ciw changes the entire inner word under the cursor, regardless of where in the word the cursor is positioned.
  • cw is technically c + w (change + word motion), while ciw is c + iw (change + inner word text object)

Example

Given the text with the cursor on the i in quick:

The quick brown fox

Pressing cw deletes only ick (from cursor to end of word) and enters insert mode:

The qu| brown fox

Pressing ciw instead deletes the entire word quick and enters insert mode:

The | brown fox

With ciw, cursor position within the word does not matter — the full word is always selected.

Another key difference

When the cursor is at the start of a word, cw and ciw produce nearly identical results. The difference only matters when the cursor is in the middle or end of a word. This is why many Vim users develop a habit of always using ciw — it is predictable regardless of cursor position.

Tips

  • Prefer ciw when you want to replace a whole word — it works consistently no matter where the cursor lands on the word
  • Prefer cw when you intentionally want to change only the tail of a word, like correcting a suffix
  • caw ("a word") changes the word plus surrounding whitespace — useful when you want to remove the word and close the gap
  • The same logic applies to delete and yank: diw vs dw, yiw vs yw
  • dw deletes the word and trailing whitespace, while de deletes only to the end of the word. But cw behaves like ce — this is a historical Vim quirk documented in :help cw
  • Text objects (iw, aw, i", a(, etc.) are almost always more predictable than motions (w, e, b) when combined with operators — learning to default to text objects will make your editing more reliable
  • Combine ciw with . to repeat: change one word, move to the next target, and press . to perform the same full-word replacement

Next

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