We changed our privacy policy. Read more.
31

You need to customize save-interprogram-paste-before-kill to t. This will push your clipboard onto the killring in case you kill something in emacs before pasting the clipboard. A related customization is yank-pop-change-selection which pushes your current yank in emacs onto the clipboard. For both of these to work, you need x-select-enable-clipboard (...


30

There is no bug here. Since I was also annoyed with this behavior, I just read Evil code to find out why this is happening. So, here is a straight copy/paste of the well-commented one-liner from my Emacs configuration that fixes this issue: ;; Imagine the following scenario. One wants to paste some previously copied ;; (from application other than Emacs) ...


22

Emacs ≤24.3 Pressing RET doesn't indent by default (except in some programming modes, for which you need to check mode-specific configuration, e.g. “electric” settings). Unix terminals normally paste a carriage return character when the clipboard contents contains a newline (represented by the line feed character). In Emacs, a carriage return looks like ...


6

You can use the external utilities xsel or xclip (they have mostly the same features, I'll use xsel in this answer) to copy data from or to the X clipboard. To copy to the clipboard, pass the desired content on standard input. When pasting from the clipboard, the content is written to standard output. To copy the selection to the X clipboard, use M-| xsel -...


6

Use kill-new instead of clipboard-kill-region for this. clipboard-kill-region uses kill-region which will append the text to the last kill if the last call was kill-region. (defun sk-copy-file-name () "Put the current file name on the clipboard" (interactive) (kill-new (or (buffer-file-name) default-directory)))


5

Here is a one-off command you can use to yank the each line of the current kill on the end of each subsequent line, starting on the current line. (defun yank-append-lines (&optional without-space) "Yank each line of the current kill at the end of each subsequent line. A space will be added between each line unless WITHOUT-SPACE which can be passed in ...


5

TL;DR: you can use clipmon available on MELPA, and turn on clipmon-mode. Note: the details below apply to X servers, but the package should work on any platform. How does the clipboard work ? Clipboard is implemented as an asynchronous process. When you copy from an application, it becomes the "clipboard owner" but doesn't actually put the copied data ...


4

The function x-select-text can be used to do this: Select TEXT, a string, according to the window system. On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the clipboard. If `x-select-enable-primary' is non-nil, put TEXT in the primary selection. So we need to setx-select-enable-clipboard to a non-nil value (e.g., t). On Linux machines, it's ...


4

Emacs Command Instead of select-and-copy manually, you can also write a command and let it do the work for you: ;; Adapted from `comint-delete-output' (defun comint-copy-output () "Copy all output from interpreter since last input." (interactive) (let ((proc (get-buffer-process (current-buffer)))) (save-excursion (let ((pmark (progn (goto-...


4

After I open a Magit status buffer and make a commit, I commonly also want to copy that commit's hash With vanilla Emacs bindings in the Magit status buffer: M-w (magit-copy-buffer-revision) saves the latest commit hash to the kill-ring: M-w runs the command magit-copy-buffer-revision (found in magit-status-mode-map), which is an interactive compiled Lisp ...


3

(defun copy-rectangle-to-system-clipboard (start end) "Like `copy-rectangle-as-kill', but also copy to system clipboard." (interactive "r") (call-interactively #'copy-rectangle-as-kill) (with-temp-buffer (yank-rectangle) (delete-trailing-whitespace) (funcall interprogram-cut-function (buffer-string)))) I have tested it using graphical ...


3

I'm not sure that it is possible to have copied text appear in your kill-ring immediately after copying, unless there is some way to run a hook on copy. This would obviously depend on your operating system/environment, but I did want to mention that you might want to try setting (setq save-interprogram-paste-before-kill t) Which will at least preserve ...


3

The linebreaks are missing because there is a conflict between your coding system on the desktop and your emacs setup. Emacs can be configured to have different coding systems for the terminal, keyboard and clipboard. Try to set your clipboard coding system and selection coding system to utf-16-le, i.e.,: (if (eq system-type 'windows-nt) (progn (...


3

I suggest you try out the xclip package, availble in GNU ELPA.


3

another solution is just use cli tool if possible, pbcopy/pbpaste on Mac getclip/putclip on Cygwin xsel on Linux x-clipboard in GUI Emacs (as others mentioned, you need turn on the flag x-select-enable-clipboard). The advantage of this solution is that the clipboard is always usable (for example, when you remote ssh). My answer has two parts. part one ...


3

The following code augments the key sequence M-w such that it copies the date below point with the format "%d.%m.%Y when region is not active ( %d: zero padded day, %m: zero-padded month, %Y: year). You can change the format with the customization option calendar-copy-as-kill-format. (defcustom calendar-copy-as-kill-format "%d.%m.%Y" "Format string for ...


3

According to documentation of the kill-ring variable, interact with the kill ring directly is not recommended: Since the kill ring is supposed to interact nicely with cut-and-paste facilities offered by window systems, use of this variable should interact nicely with interprogram-cut-function and interprogram-paste-function. The functions kill-new, ...


3

C-a C-SPC C-e M-w does work in all versions of Emacs. The only reason it doesn't work for you is that you've changed the key bindings. If you're using a GUI Emacs, you can use home S-end C-insert or Home S-End M-w instead. This may or may not work in a terminal, depending on how the terminal passes function keys to Emacs. I'm can't use C-a because this ...


2

Gilles's solution actually exists as a package, called xclip available from GNU ELPA. I.e. install it from M-x list-packages and then enable it with M-x xclip-mode RET. See also Clipboard manager will not work in terminal Emacs which is basically the same question.


2

The NEWS for 25.1 says: *** Killing text now also sets the CLIPBOARD/PRIMARY selection in the surrounding GUI (using the OSC-52 escape sequence). This only works if your xterm supports it and enables the 'allowWindowOps' options (disabled by default at least in Debian, for security reasons). Similarly, you can yank the CLIPBOARD/PRIMARY selection (using ...


2

Try the following: (setq interprogram-paste-function nil)


2

Finally I figured out a clumsy solution, which referred to the concept of clipmon. But very simple with one line's code: (run-at-time 0 3 (lambda () (interactive) (current-kill 0))) The kill ring will be synchronized every 3 seconds with system clipboard. Of course you can alter the interval to a even smaller value. PS: The reason why I need this ...


2

This should do the trick :- (setq select-active-regions 'only) This will make sure that emacs will only save the temporarily active regions to the primary selection, i.e those made with the mouse or shift keys.


2

By default (at least in Emacs 25), <S-Insert> is bound to the same command as C-y: they both invoke the yank command. You could try rebinding one of the them to clipboard-yank instead. (global-set-key (kbd "<S-Insert>") #'clipboard-yank)


2

Step 1: Select text and M-x diff-region-tag-selected-as-a Step 2, Select or not select text, M-x diff-region-tag-selected-as-b You need install cli tool diff on windows (its bundled with Cygwin or MSYS2). To read clipboard, you need install Emacs plugin simpleclip. Here is the code: ;; {{ diff region SDK (defun diff-region-exit-from-certain-buffer (...


2

After reading Primary Selection I got a clue for the solution. A simple deactivate-mark did the trick for me: (defun copy-no-white-space () (interactive) (deactivate-mark) (gui-set-selection 'PRIMARY (replace-regexp-in-string "[\s\n]" "" (buffer-substring (region-beginning) (region-end)))) My interpretation is the following: After leaving the ...


2

You're in luck; this is already built in. C-y yanks the last thing that you've killed or copied, and M-y replaces it with the next item from the kill-ring, which contains everything you've killed or copied in your current Emacs session.


2

No. M-DEL is bound to the function backward-kill-word, which calls kill-region. Anything that calls kill-region puts the killed text into the kill-ring, and also into the system clipboard. This is what differentiates the “kill commands” from commands that merely delete text from the buffer. You could call delete-region instead, or you could paste from the ...


2

In modern versions of Emacs, by default, delete-backward-char (DEL, i.e. BackSpace) deletes the region if it is active. So you can delete instead of killing by selecting, then pressing DEL. If you want C-d or delete (Del) to do that, bind them to delete-forward-char instead of the default delete-char. If you enable delete-selection-mode, then most commands ...


1

As the message says: Saving clipboard to x clipboard manager... Try emacs -Q and copy then close emacs, you get this message: Error saving to X clipboard manager. If the problem persists, set 'x-select-enable-clipboard-manager' to nil. So add (setq x-select-enable-clipboard-manager nil) to your .emacs file


Only top voted, non community-wiki answers of a minimum length are eligible