How to copy text in Emacs Evil-Mode without overwriting the clipboard?

modulitos picture modulitos · Oct 20, 2014 · Viewed 9.7k times · Source

This post described how to do it in Vim, where one prefixes their copy command with " + <register name> (ie k). How can I do this in Emacs Evil-Mode?

For example, I tried the following:

  • yy - copy first line to clipboard
  • jjj - move to some new line
  • "kyy - copy second line to register k
  • Move to my new region
  • p - paste first line
  • "kp - paste second line

However, at p, Emacs pastes my second line, as if the register was ignored and copied directly to the clipboard. Any suggestions on how to use Vim-like registers? If not, any suggestions on how to copy and paste multiple regions in Evil-Mode?

Answer

idbrii picture idbrii · Mar 17, 2015

I think setting this value will do it:

(setq x-select-enable-clipboard nil)

Using evil (in spacemacs), "+y still copies to clipboard, so I think that should work.


If not, this blog post describes a more verbose method: Write handlers for all ways you can delete to avoid touching the clipboard and rebind keys to use these handlers.