A very common use case I'm having is to copy something (let's say a word) and I want to paste it in another context (let's say a word with quotes). The way I do it is:

const char *foobar(void) {
    return "barfoo";

there, as my cursor is on foobar:

const char *foo|bar(void) {

I could do something like:


to copy content. Then:


to move within the returned string:

    return "bar|foo";

And then I should do:


to paste foobar within the quotes:

    return "foobar|";

My question is whether there's a way to use a motion to put, the same way it is possible to yank, what I'd love to do is something like:


which obviously wouldn't work. I find it feels weird to have to use a visual to apply a paste within a motion, but everybody I asked told me it's not possible. If it is indeed not, what would be the rationale of having the action put not accepting a motion‽


Well, assuming pi" would work, it would then mean that you will need at least 2 chars to simply put at cursor position - you can't simply use p by itself! (which is, after all, the most often used paste operation). With yank, it's clear you have to copy "something", so there is an asymmetry between the two.

BTW, with Kana's operator replace, you can simply do something like _i" to replace text with previous yanked text from default register. Or __ to replace a line (assuming you mapped _ as the docs suggest).

  • well, I agree <kbd>p</kbd> is the most used put operation, but it's behaviour is always assuming a lot in how and where to put. Putting something taken by <kbd>C-v</kdb> will behave differently than when it's taken by <kbd>yiw</kdb. and yet differently than with <kbd>yy</kbd>, which might not always be the preferred way to put. So the default <kbd>p</kbd> seems odd and not in line with general behaviour. The operator replace sounds interesting though, I'll give it a try ;-)
    – zmo
    Sep 6 '15 at 23:54
  • You asked about a rationale: yank "something" (range) != put "somewhere" (position). If p would accept a range (motion, text-object), you couldn't use p alone. I'm not saying that I like it, that I agree with it etc. - it's just why I think it is like it is.
    – VanLaser
    Sep 7 '15 at 10:31
  • A few other plugin options: ReplaceWithRegister and regreplop.vim. Sep 8 '15 at 17:12
  • 2
    I'm giving a try to kana's operator-replace, and it's very likely I'll like it, and I might actually consider replace p with it (and then gp with p to keep the old behaviour within easy reach) :->
    – zmo
    Sep 9 '15 at 7:56

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.