Search code examples
vimneovim

How to disable clipboard for cutting command like dd, daw etc, but keep for commands like yy, yaw etc?


Problem:

I started to use Neovim. I like the flexibility of removing characters; however, it does not work with the following flow I have always used.

Let's say I want to change the image source on <img src="image1.png">

  1. I open a browser and copy the URL on Imgur, so in the OS system buffer, I have now https://imgur.com/a/xxxxx
  2. I edit index.html and press di" to delete inside quotes and then want to paste my URL, but I can't cause my clipboard just changed to image1.png.
  3. So I have to go to the browser again, copy the URL, and paste it into Neovim.

How can I turn off such clipboarding? If I need clarification on something conceptually, please point me the right way. Appreciate.


Solution

  • How can I turn off such clipboarding?

    You don't. You learn to use it properly, as well as the rest of the editor.

    In this case, you would do:

    vi"p
    

    if you have either unnamed or unnamedplus in :help clipboard, or either of:

    vi""+p
    vi""*p
    

    if you don't, depending on how you copied the URL in your browser.

    • vi" visually selects the content of a quoted string, see :help v, :help i", and more generally :help motion.txt.

    • [reg]p puts from the given register…

      • p alone puts from the "" ("unnamed")register, see :help quotequote,
      • "+p puts from the "+ ("clipboard") register, see :help quoteplus,
      • "*p puts from the "* ("primary") register, see :help quotestar.

    Also, the last thing you yanked is always in register "0.

    NOTE: it is possible that Neovim handles things a bit differently than Vim under the hood but I don't use it so YMMV.