How to replace a single word under cursor?

ciw

c   change
iw  inner word

This will delete the word under the cursor (even if the cursor is somewhere in the middle of the word) and enter insert mode.


Also see Vim's documentation for reference:

:help c
:help text-objects

ciw

(change inner word) will change the whole word under the cursor. Compare with

cw

which will only change the word from the current cursor position. For more info see this SO question/answer.


I often find myself wanting to replace one word with another that I have yanked from elsewhere. The problem with the other solutions is that if you attempt to change a word, then your next paste will be that word that you deleted with cw.

Try the following:

1 "This first word should overwrite the second"

yiw     yank inner word (copy word under cursor, say "first").
...     Move the cursor to another word (say "second").
viwp    select "second", then replace it with "first". 

Hope that's what you were looking for.

Tags:

Vim

Replace