How to stop Emacs from “contaminating” the clipboard?

让人想犯罪 __ 提交于 2019-12-05 05:56:29

First off: Emacs has its own internal "clipboard" called "kill ring" which is separate from the system clipboard.

To make sure the system clipboard always has the latest content you copied outside of Emacs, add

(setq x-select-enable-clipboard nil)

to your .emacs file. According to the Emacs manual, this will

prevent kill and yank commands from accessing the clipboard [...].

Irrespective of whether you've killed text inside of Emacs after copying content outside of it, you can then use the command x-clipboard-yank to insert the contents of the clipboard into the current buffer. If you want, you can set up a global key binding for this command via

(global-set-key (kbd "C-c y") 'x-clipboard-yank)

If necessary, replace C-c y with a key binding of your choosing.

Use delete-region. Commonly commands having delete in their names don't store the stuff in kill-ring.

These two settings prevent X clipboard contamination. All kill rings stay intact inside Emacs.

  (setq x-select-enable-clipboard nil)
  (setq x-select-enable-primary nil)

To solve the specific problem of needing to delete something before pasting in the replacement text, just use delete-selection-mode. This makes it so that the region is deleted when you paste.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!