On Mon, 19 Jun 2006, Tim Chase wrote:

What would be the quickest way of yanking one word and
replacing another word with it? Something that doesn't involve
specifying registers, because that would require too many
keystrokes and I might as well use cw and type the word myself
then.

You don't mention whether you only want to do this once, or if you have a whole bunch to perform.

If you just need to do it once, you can use

        vwp

or

        viwp

on your target word, and it should replace it with whatever was in your scrap register (that you yanked previously). It has the unfortunate (well, it could be fortunate in certain circumstances, but this isn't one of them) side effect of then replacing your scrap register's contents with the word that was just replaced, meaning you can't repeat the process elsewhere, and still get the same results (with the original contents of the scrap register).

One solution might be something like

nnoremap <f4> "_ciw<c-r>"<esc>

which will replace the word currently under the cursor with the contents of the scrap register, and not tromp over it with the contents of the replaced word. It makes use of the black-hole register:

        :help quote_

Another workaround would be to paste from register 0 (zero):

  noremap <Leader>p "0p
  noremap <Leader>P "0P

Then you would do this instead:

  viw\p

assuming your <Leader> key is a backslash.

See

  :help quote0

HTH.
--
Gerald

Reply via email to