Basically the opposite of this question.

This is on macOS.

I copy from a program using ⌘C and I want to add that text to "" or "0 so when I cw or something similar I don't obliterate my copied text. How do I paste to the register?

  • 2
    Hello and welcome to Vi and Vim! I'm having some trouble understanding your question. Are you saying that when you use Cmd+C from a different application, it overrides your register in Vim such that you can't paste those contents anymore? How is the cw command related here? Why do you think the unnamed ("") register is getting involved? Do you happen to have autocmds or plugins syncing your clipboard with Vim? Are you using Vim on terminal or MacVim and which version? Please edit the question to add more details, try to give a step-by-step of how you reproduce your problem. Thanks! – filbranden Apr 28 at 23:32
  • 1
    I'm also unclear about whether you're looking for an action you can invoke in Vim on specific occasions, or if you want something that happens automatically in Vim every time you press ⌘C outside of Vim. – Rich Apr 29 at 8:35
  • 1
    :let @register=@+? – Christian Brabandt Apr 29 at 12:28
  • Does this answer your question? How can I copy text to the system clipboard from Vim? – Martin Tournoij 2 days ago

I think there's no way to do what you want (i.e. populate the "" register from external apps but without touching it from vi), but there's a workaround. It may not be exactly what you expect, but it is worth a try (at least this is how I work and I don't miss the default behaviour at all):

  1. Configure the clipboard as explained in the post you linked.
  2. Use the "black hole" register (:help quote_) when you change, paste, or delete things. Because it is tedious to do so manually, you can map the desired operators:
noremap d "_d
noremap dd "_dd
noremap D "_D
noremap x "_x
noremap X "_X

noremap c "_c
noremap cc "_cc
noremap cl "_cl
noremap C "_C

xnoremap p "_dP

I also use shortcuts for yank and delete at the same time:

noremap yd d
noremap yD D
noremap ydd dd

Of course, this means that no changed text would be kept on any register unless you manually yank it before it is changed or, you manually chose another register. I may be missing something, but to be honest I don't relly on vi registers at all, especially because I use a little app that provides system-wide "registers"

| improve this answer | |

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