1

I want to paste data from clipboard. But instead of insert the data, I want to overwrite (like using R).

1
  • 2
    Can we have an example?
    – romainl
    Commented Dec 5, 2023 at 13:06

3 Answers 3

3

You can visual-select the text you want to overwrite and then paste from clipboard. For a single word, that would be ve to select until the end of the word to replace and "+p to insert the clipboard's contents over the selection.

Works especially well if the text to replace and the text to insert differ in lengths.

5
  • @Antonio I really appreciate your edit to my answer. However, I can't get it to work, at least not from clipboard (it's probably me). Therefore, I removed the sentence again. Hope to see an answer of your own explaining your idea.
    – Friedrich
    Commented Dec 5, 2023 at 19:38
  • I think the key is "the last visual operation". If you do a visual selection but no operation on the selected text, it don't works. Indeed it works if you make a visual selection and then yank the text. I restore the part with gif to show how it works.
    – Antonio
    Commented Dec 18, 2023 at 16:57
  • 1
    @Antonio this is getting a little bit surreal, me arguing with my own post. I think OP's first sentence is key: "I want to paste data from clipboard." i.e. not from a buffer. What you write is neat, it's great, it also doesn't actually answer the question IMHO. Hence my reservations. Please do write an answer of your own. Your edits earned you 4 rep while what you write (with that nice animated gif) is good for at least two upvotes or 20 rep.
    – Friedrich
    Commented Dec 18, 2023 at 17:50
  • You are right. I did a mistake between register and clipboard. And I understand, it' is funny to edit and re-edit your post, I thought there was a simpler way to reply to your comment. 😅 Thanks for your kind way to reply to me and to delete my OT additions. :-)
    – Antonio
    Commented Dec 19, 2023 at 14:30
  • P.S. I spent one hour and half to figurate how to record the vim window with keys I pushed. 😅
    – Antonio
    Commented Dec 19, 2023 at 14:34
2

I would do:

  1. R go to replace mode
  2. Ctrl r* paste

Remark: if you have yank the clipboard from a visual selection you could also do:

  1. 1v replicate the visual selection shape from the original visual selection
  2. p paste over

You could use that technique even if the clipboard has not been yanked using visual selection by "forcing" it:

  1. P past before
  2. v go to visual mode
  3. `. got the start of the edition
  4. y yank again
  5. v leave visual mode
  6. l go no next character
  7. 1v restore selection
  8. d delete the part that you would like to override
1

If your terminal supports bracketed paste, I would expect R<paste> to work fine, where <paste> is something like Ctrl/Cmd-V, or a middle click, or whatever your system’s paste command is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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