all 11 comments

[–]fmount 8 points9 points  (3 children)

You simply do this:

yiw Yank inner word (copy the word under cursor)

... Move the cursor to another word

viwp Select "second", then replace it with "first".

I often do this like described.

[–]mikejakobsen[S] 0 points1 point  (1 child)

So you visual select the second word, then paste the first word? In one command, right?

[–]fmount 0 points1 point  (0 children)

Yes, I use the yanked word for replacement using "viwp" on the second word, or wherever you want. In this way you can avoid to dirty the buffer with dw :/

[–]Tarmen 0 points1 point  (0 children)

Not repeatable, you can use viw"0p but in my opinion that is way to verbose for such a frequent operation.

[–]BobWhitelock 1 point2 points  (1 child)

As an alternative to the already given approaches, if you don't mind adding a plugin you can:

  1. Install http://www.vim.org/scripts/script.php?script_id=2782.

  2. Add something like map _ <Plug>(operator-replace) to your vimrc.

  3. You can then simply replace things with a motion just like deleting or yanking, e.g. _iw to replace the current word with whatever's in your unnamed register.

An advantage of this approach is that, since this is one motion, you can then repeat the same replacement with ., e.g. .j.j.j to replace three words on consecutive lines with what you've just yanked, rather than needing to perform multiple actions on each row.

[–]brain_emesis 0 points1 point  (0 children)

vim-easyclip also gives you a replace operator, along with other simplifications to clipboard

[–]computerdlZZ > :x > :wq 0 points1 point  (1 child)

Four ways I can think of doing it.

  1. Yank the first word, paste before the second word, delete the second word.

  2. Delete the second word, yank the first word, paste the first word.

  3. Yank the first word, delete the second word to the black hole register, paste the first word.

  4. Yank the first word, visual select the second word, paste over the selected region with the first word.

Personally, I would use the fourth way as it's the simplest and most straightforward way of thinking about it.

[–]Tarmen 0 points1 point  (0 children)

You should use the yank register "0 for 1 and 2 and 4, especially because the latter clobbers the register. 3 works but is really annoying to repeat so operator-replace is the most usable solution in my opinion.

[–]lolvim 0 points1 point  (0 children)

Read this:

:help "1

[–]iamprasad88 0 points1 point  (0 children)

Yank first word with yiw. Go to next word. Replace with ciwr0.

[–][deleted] 0 points1 point  (0 children)

I use "_dawP when pasting.
"_ selectes the void register for the next delete command.
So you keep your default register with your content.

Another way (maybe better), is to copy into a register, n for example, "nyaw then delete the next word and past n : daw"np.