6

Basically, I need advice on how to do the opposite of what is described here:

How to make vim paste from (and copy to) system's clipboard?

I do not want vim to overwrite system clipboard when I delete something within the editor. The usual workflow for me is to select a piece of code (let us call it piece #1) with a mouse, then go to another piece of code (let us call it piece #2), select piece #2 in visual mode in vim, delete it using "c", and paste piece #1 using mouse middle button. With the new behavior, instead of pasting piece #1 I paste back piece #2.

In vim 7.2 I can do that, but in vim 7.4 I can not. I want to use 7.4 due to proper C++11 syntax highlighting but this changed default behavior is killing me.

I think, it has something to do with the "+xterm_clipboard" and/or "+clipboard" features of vim (vim --version), and I need to change them somehow to "-xterm_clipboard" and/or "-clipboard". I tried to recompile vim 7.4 with the option "--with-x=no" but somehow it did not help.

Please, help me to disable copying/pasting in vim to system clipboard by default.

Thank you!

Community
  • 1
  • 1
S.V
  • 1,008
  • 10
  • 20
  • You have two options. First, better avoid that clipboard register. Second, map it or set it to other register. :) – SibiCoder Jul 27 '16 at 15:51

2 Answers2

12

Well, to answer the question in your title, you can just do

:set clipboard=

Which will make vim use it's internal register instead of the system one.

But really, this behavior has nothing to do with the system clipboard. It's more just a general misunderstanding of vim registers.

Vim by default "cuts" rather than "deletes". This means that every delete command (c and d) yanks to the unnamed register at the same time. To get around this, just use the black hole register, e.g. use "_c or "_d instead of just doing c or d.

9. Black hole register "_               *quote_*
When writing to this register, nothing happens.  This can be used to delete
text without affecting the normal registers.  When reading from this register,
nothing is returned.  {not in Vi}

To make this the default behavior for your specific case, you can do

xnoremap c "_d

The 'x' in 'xnoremap' means this mapping applies to visual mode (with v) and select mode (with the mouse)

Related SO link.

Community
  • 1
  • 1
DJMcMayhem
  • 6,593
  • 3
  • 35
  • 52
  • (this is a comment to the previous version of your reply) Thank you very much! **":set clipboard="** does the trick for me :) If you reverse your answer back to advice me to ":set clipboard=", I will accept it ;) – S.V Jul 27 '16 at 20:27
  • @S.V Glad I could help! Also, just so you know, there is also a [dedicated vim site](http://vi.stackexchange.com/) if you have more questions down the road. – DJMcMayhem Jul 27 '16 at 20:36
  • Thank you! Indeed, I did not know about http://vi.stackexchange.com/ - somehow my google searches led me here, instead of the dedicated vim site. – S.V Jul 27 '16 at 20:41
0

check

:h clipboard-unnamed

This extension may be also of use to you http://vimawesome.com/plugin/easyclip

P4C
  • 477
  • 5
  • 10