Assume I have the text Fnord yanked before and that my cursor resides on the B of the line:


How can I change the text inside () with the previously yanked text?

Currently, I often make the mistake by doing:

  • di( aka "delete inside ()"

yet which leaves me with the exact text again, as the deleted text will be moved to the register.

I want to have:

  • 2
    Possible duplicate of How to replace a word with a yanked word in normal mode – Rich Jan 20 '16 at 16:52
  • 1
    @Rich The provided question covers the more general case of replacing a yanked word. I think this question is a bit more specific and does not attract the same answers. – k0pernikus Jan 20 '16 at 17:30
  • Protip: The 0 register will contain the last yanked text. :h quote0 – Peter Rincker Jan 20 '16 at 20:54
  • 1
    The same idea from the mentioned question's accepted answer can be applied here. With the cursor in the parentheses, simply press vi)p. It is the same as in that answer, just with the i) text object instead of the w text object, – EvergreenTree Jan 21 '16 at 2:10
  • 1
    @k0pernikus I'm afraid we'll have to agree to disagree on that one. To me, the important part of both questions is the replacement, and not the text object used to apply it. – Rich Jan 21 '16 at 11:17

You can use visual selection to select the text to replace, and then paste over it as follows:


vi( selects Baz (because it is enclosed in parenthesis), p pastes Fnord over it.

However, this will yank Baz to the register after the paste, which might not be what you want.

| improve this answer | |

Unless you specify a register, p (or P) will use the last register that was filled. The unnamed register "" contains the most recently yanked or deleted text (unless another register was specified, e.g. with "ay), but these also go into "0 for yanks or "1 for deletes/changes. See registers.

If the last text was yanked with y you can paste it from the 0 register with "0P. If it was deleted, you could access it with the 2 register with "2P ("1 is now Baz).

Alternatively you could avoid messing with your registers and delete to the blackhole register "_:

| improve this answer | |

If installing plugins is an option, you could use yankstack.vim. Then you could retain you current workflow:

Currently, I often make the mistake by doing:

  • di( aka "delete inside ()"
  • Alt+p - cycle to the previous yank
| improve this answer | |

Assuming "Fnord" is in register a you can do (with the cursor at the beginning of the line) f(ci(<c-r>a

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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