Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to substitute a word in-place. For example, after yanking some word by pressing yw and then setting a cursor on some other word, I would like to press something so that substitution will happen. (e.g. SOME_KEYw where w is really w and SOME_KEY is some key). I would not like to switch into Insert Mode.

I am not interested in the :%s/oldword/newword/gc solution. I need interactive in-place substitution!

share|improve this question
up vote 7 down vote accepted

What you are looking for is described in Vim Tip 605.

If you yank the first word with yiw, you can then replace another word with the first one by typing viwp.

If you leave out the i, yw will also yank the whitespace after your word and when pasting this you get too much spaces. Therefore, use i to select the inner word.

share|improve this answer
I don't like this solution because it is counterintuitive; instead of "viwp" different typos happen like "iwvp", "wivp", ... Very bad... – psihodelia Dec 3 '09 at 13:56
So maybe you shouldn't be using vim in the first place? Because typos might happen? – innaM Dec 3 '09 at 13:58
I am with vim since many years. A solution presented by Rene is better because it doesn't require typing "yiw" but only usual "yw"="Yank Word". But of course his solution is also bad because it requires key pressing 2+5 times to make only one substitution. Your solution requires pressing 3+4 times. – psihodelia Dec 3 '09 at 14:51
If you want "intuitive", you're using the wrong text editor. – Lawrence Velázquez Dec 4 '09 at 6:48
I think that this is quite intuitive. First, yank the inner word, then visually select the inner word and paste. That's exactly what you would do with some visual editor using the mouse. – innaM Dec 4 '09 at 9:48

I believe you want cw<CTRL-R>0

This is to be typed as cwctrl+r0.

share|improve this answer
thanks but it is very uncomfortable and it switches edition mode to -Insert- – psihodelia Dec 3 '09 at 11:40
then create a map – René Nyffenegger Dec 3 '09 at 11:50
What does CTRL+R, 0 do? – Nathan Fellman Dec 3 '09 at 12:14
The letter typed after CTRL+R is the name of the register whose content is to be filled in. See :help i_CTRL-R – René Nyffenegger Dec 3 '09 at 12:23
should probably be added that he should be standing at the first letter of the word ... – Rook Dec 3 '09 at 14:00

Building upon innaM's answer, with shorter input:

First copy the first word with ye.

Then replace any other word with this previously copied word with vep.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.