8

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?

Community
  • 1
  • 1
modulitos
  • 14,737
  • 16
  • 67
  • 110
  • does `:registers` show anything in register `k` after you typed `"ky`? – kiritsuku Oct 21 '14 at 08:14
  • Yes, register `k` stores my copied text, but my clipboard is also replaced with the copy text. How can I retain the clipboard contents when copying in evil-mode? – modulitos Oct 23 '14 at 02:52

3 Answers3

13

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.

idbrii
  • 10,975
  • 5
  • 66
  • 107
  • Wow, that blogpost is exactly what I've needed. It solves my problem perfectly! And the code is very clean and modular ;-) – modulitos Mar 17 '15 at 06:56
  • This does not work in emacs started as "emacs -nw", i.e, working in the terminal. Can you suggest some alternative which would work in the terminal too? – enitihas Mar 19 '16 at 10:43
  • @enitihas: I don't know. I don't see how `yy` in terminal could be very different from windowed. You'll probably need to ask a new question specific to the terminal (include a link to this question too!). – idbrii Apr 05 '16 at 17:34
  • Hello @Lucas, I'm looking for the same thing, did you have the code to fix this? I'm asking you because now the link to that blogpost is broken. Thanks! – zzantares May 10 '16 at 23:59
  • @ZzAntáres Sorry about the broken link! It's disappointing when that happens. But here is the code that should do the trick: https://github.com/LukeSwart/.emacs.d/blob/master/modes.el#L386-L479 Keep in touch if you have any issues! – modulitos May 11 '16 at 01:08
  • Fixed link to use wayback machine. – idbrii May 18 '16 at 05:10
2

This is 100% the solution, if you're spacemacs and probably otherwise:

(fset 'evil-visual-update-x-selection 'ignore)

Credit to: https://emacs.stackexchange.com/a/15054/8377

Community
  • 1
  • 1
justingordon
  • 12,553
  • 12
  • 72
  • 116
1

It behaves similarly in vim. Numerical registers get overwritten no matter what register you intended to use. Running your examples in both Emacs (w/ evil of course) and Vim I get the k register filled up correctly and under register 0, the most recent yank that happens to be the same as in k.

mike3996
  • 17,047
  • 9
  • 64
  • 80
  • This is not to be regarded as the correct answer as I would also prefer to hear a fix to this small annoyance. – mike3996 Oct 21 '14 at 10:19
  • 1
    Check out idbrii 's answer above. His linked blog post seems to solve this issue perfectly. – modulitos Mar 17 '15 at 06:59