<p>When I cut (kill) text in Emacs 22.1.1 (in its own window on X, in KDE, on Kubuntu), I can't paste (yank) it in any other application.</p>

[{'answer_id': 64406, 'author': 'kfh', 'author_id': 6597, 'author_profile': 'https://Stackoverflow.com/users/6597', 'pm_score': 0, 'selected': False, 'text': '<p>Hmm, what platform and what version of emacs are you using?  With GNU Emacs 22.1.1 on Windows Vista, it works fine for me.</p>\n\n<p>If, by any chance, you are doing this from windows to linux through a RealVNC viewer, make sure you are running "vncconfig -iconic" on the linux box first.....</p>\n'}, {'answer_id': 64410, 'author': 'warren', 'author_id': 4418, 'author_profile': 'https://Stackoverflow.com/users/4418', 'pm_score': -1, 'selected': False, 'text': '<p>What I do is to use a good terminal tool (PuTTY on Windows, Konsole or Terminal on Linux) that has copy facilities built-in.</p>\n\n<p>In PuTTY, you highlight the text you want with the mouse and then paste it elsewhere. Right-clicking in a PuTTY window pastes the contents of the Windows copy/paste buffer.</p>\n\n<p>In Konsole or Terminal on Linux, you highlight what you want then press Shift+Ctrl+C for copy and Shift+Ctrl+V for paste.</p>\n\n<p>In the win32 compile of emacs, yanking text does put it on the copy/paste buffer .. most of the time.</p>\n\n<p>On Mac OS X, the Apple-key chortcuts work fine, because Terminal traps them.</p>\n\n<p>There is no direct way of doing it on the commandline because the shell does not maintain a copy/paste buffer for each application. bash <em>does</em> maintain a copy/paste buffer for itself, and, by default, emacs ^k/^y shortcuts work.</p>\n'}, {'answer_id': 64412, 'author': 'cannam', 'author_id': 8608, 'author_profile': 'https://Stackoverflow.com/users/8608', 'pm_score': 0, 'selected': False, 'text': "<p>I always use quick paste -- drag selection in emacs, hit the middle mouse button in target window.</p>\n\n<p>(From the reference to kate, I take it you're on linux or similar and probably using emacs in X one way or another.)</p>\n"}, {'answer_id': 64415, 'author': 'Mats Fredriksson', 'author_id': 2973, 'author_profile': 'https://Stackoverflow.com/users/2973', 'pm_score': 0, 'selected': False, 'text': "<p>You might want to specify what platform you are using. Is it on linux, unix, macosx, windows, ms-dos?</p>\n\n<p>I believe that for windows it should work. For MacOSX it will get added to the x-windows clipboard, which isn't the same thing as the macosx clipboard. For Linux, it depends on your flavour of window manager, but I believe that x-windows handles it in a nice way on most of them.</p>\n\n<p>So, please specify.</p>\n"}, {'answer_id': 64440, 'author': 'cschol', 'author_id': 2386, 'author_profile': 'https://Stackoverflow.com/users/2386', 'pm_score': 3, 'selected': False, 'text': '<p>There is <a href="http://www.emacswiki.org/emacs/CopyAndPaste" rel="nofollow noreferrer">an EmacsWiki article</a> that explains some issues with copy &amp; pasting under X and how to configure it to work.</p>\n'}, {'answer_id': 64466, 'author': 'pdq', 'author_id': 8598, 'author_profile': 'https://Stackoverflow.com/users/8598', 'pm_score': 3, 'selected': False, 'text': '<p>I assume by emacs you are meaning Emacs under X (ie not inside a terminal window).</p>\n\n<p>There are two ways:</p>\n\n<ol>\n<li>(Applies to unix OS\'s only)\nHighlight the desired text with your\nmouse (this copies it to the X\nclipboard) and then middle click to\npaste.</li>\n<li>Highlight the desired text and then "M-x clipboard-kill-ring-save"\n(note you can bind this to an easier\nkey).  Then just "Edit->Paste" in\nyour favorite app.</li>\n</ol>\n\n<p>Clipboard operations available:</p>\n\n<ul>\n<li>clipboard-kill-ring-save -- copy\nselection from Emacs to clipboard</li>\n<li>clipboard-kill-region -- cut\nselection from Emacs to clipboard</li>\n<li>clipboard-yank -- paste from\nclipboard to Emacs</li>\n</ul>\n'}, {'answer_id': 64558, 'author': 'memius', 'author_id': 8522, 'author_profile': 'https://Stackoverflow.com/users/8522', 'pm_score': 8, 'selected': True, 'text': '<p>Insert the following into your <code>.emacs</code> file:</p>\n\n<pre><code>(setq x-select-enable-clipboard t)\n</code></pre>\n'}, {'answer_id': 65473, 'author': 'Chris Conway', 'author_id': 1412, 'author_profile': 'https://Stackoverflow.com/users/1412', 'pm_score': 7, 'selected': False, 'text': '<p>Let\'s be careful with our definitions here</p>\n\n<ul>\n<li>An <em>Emacs copy</em> is the command <code>kill-ring-save</code> (usually bound to <kbd>M-w</kbd>).</li>\n<li>A <em>system copy</em> is what you typically get from pressing <kbd>C-c</kbd> (or choosing "Edit->Copy" in a application window).</li>\n<li>An <em>X copy</em> is "physically" highlighting text with the mouse cursor.</li>\n<li>An <em>Emacs paste</em> is the command <code>yank</code> (usually bound to <kbd>C-y</kbd>).</li>\n<li>A <em>system paste</em> is what you typically get from pressing <kbd>C-v</kbd> (or choosing "Edit-Paste" in an application window).</li>\n<li>An <em>X paste</em> is pressing the "center mouse button" (simulated by pressing the left and right mouse buttons together).</li>\n</ul>\n\n<p>In my case (on GNOME):</p>\n\n<ul>\n<li>Both Emacs and system copy usually work with X paste.</li>\n<li>X copy usually works with Emacs paste.</li>\n<li><p>To make system copy work with Emacs paste and Emacs copy work with system paste, you need to add <code>(setq x-select-enable-clipboard t)</code> to your <code>.emacs</code>. Or try </p>\n\n<pre><code>META-X set-variable RET x-select-enable-clipboard RET t\n</code></pre></li>\n</ul>\n\n<p>I think this is pretty standard modern Unix behavior.</p>\n\n<p>It\'s also important to note (though you say you\'re using Emacs in a separate window) that when Emacs is running in a console, it is completely divorced from the system and X clipboards: cut and paste in that case is mediated by the terminal. For example, "Edit->Paste" in your terminal window should act exactly as if you typed the text from the clipboard into the Emacs buffer. </p>\n'}, {'answer_id': 69657, 'author': 'jfm3', 'author_id': 11138, 'author_profile': 'https://Stackoverflow.com/users/11138', 'pm_score': 4, 'selected': False, 'text': "<p>I stick this in my .emacs:</p>\n\n<pre><code>(setq x-select-enable-clipboard t)\n(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)\n</code></pre>\n\n<p>I subsequently have basically no problems cutting and pasting back and forth from anything in Emacs to any other X11 or Gnome application.</p>\n\n<p>Bonus: to get these things to happen in Emacs without having to reload your whole .emacs, do C-x C-e with the cursor just after the close paren of each of those expressions in the .emacs buffer.</p>\n\n<p>Good luck!</p>\n"}, {'answer_id': 19625063, 'author': 'RussellStewart', 'author_id': 2237635, 'author_profile': 'https://Stackoverflow.com/users/2237635', 'pm_score': 4, 'selected': False, 'text': '<p>The difficulty with copy and paste in Emacs is that you want it to work independently from the internal kill/yank, and you want it to work both in terminal and the gui. There are existing robust solutions for either terminal or gui, but not both. After installing xsel (e.g. <code>sudo apt-get install xsel</code>), here is what I do for copy and paste to combine them:</p>\n\n<pre><code>(defun copy-to-clipboard ()\n  (interactive)\n  (if (display-graphic-p)\n      (progn\n        (message "Yanked region to x-clipboard!")\n        (call-interactively \'clipboard-kill-ring-save)\n        )\n    (if (region-active-p)\n        (progn\n          (shell-command-on-region (region-beginning) (region-end) "xsel -i -b")\n          (message "Yanked region to clipboard!")\n          (deactivate-mark))\n      (message "No region active; can\'t yank to clipboard!")))\n  )\n\n(defun paste-from-clipboard ()\n  (interactive)\n  (if (display-graphic-p)\n      (progn\n        (clipboard-yank)\n        (message "graphics active")\n        )\n    (insert (shell-command-to-string "xsel -o -b"))\n    )\n  )\n\n(global-set-key [f8] \'copy-to-clipboard)\n(global-set-key [f9] \'paste-from-clipboard)\n</code></pre>\n'}, {'answer_id': 28902747, 'author': 'cevaris', 'author_id': 3538289, 'author_profile': 'https://Stackoverflow.com/users/3538289', 'pm_score': 3, 'selected': False, 'text': '<p>This works with <code>M-w</code> on Mac OSX. Just add to your <strong>.emacs</strong> file.</p>\n\n<pre><code>(defun copy-from-osx ()\n   (shell-command-to-string "pbpaste"))\n(defun paste-to-osx (text &amp;optional push)\n   (let ((process-connection-type nil))\n      (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))\n         (process-send-string proc text)\n         (process-send-eof proc))))\n\n(setq interprogram-cut-function \'paste-to-osx)\n(setq interprogram-paste-function \'copy-from-osx)\n</code></pre>\n\n<p>Source <a href="https://gist.github.com/the-kenny/267162" rel="noreferrer">https://gist.github.com/the-kenny/267162</a></p>\n'}, {'answer_id': 45417273, 'author': 'user1404316', 'author_id': 1404316, 'author_profile': 'https://Stackoverflow.com/users/1404316', 'pm_score': 1, 'selected': False, 'text': '<p>The code below, inspired by @RussellStewart\'s answer above, adds support for x-PRIMARY and x-SECONDARY, replaces <code>region-active-p</code> with <code>use-region-p</code> to cover the case of an empty region, does not return silently if xsel has not been installed (returns an error message), and includes a "cut" function (emacs C-y, windows C-x).</p>\n\n<pre><code>(defun my-copy-to-xclipboard(arg)\n  (interactive "P")\n  (cond\n    ((not (use-region-p))\n      (message "Nothing to yank to X-clipboard"))\n    ((and (not (display-graphic-p))\n         (/= 0 (shell-command-on-region\n                 (region-beginning) (region-end) "xsel -i -b")))\n      (error "Is program `xsel\' installed?"))\n    (t\n      (when (display-graphic-p)\n        (call-interactively \'clipboard-kill-ring-save))\n      (message "Yanked region to X-clipboard")\n      (when arg\n        (kill-region  (region-beginning) (region-end)))\n      (deactivate-mark))))\n\n(defun my-cut-to-xclipboard()\n  (interactive)\n  (my-copy-to-xclipboard t))\n\n(defun my-paste-from-xclipboard()\n  "Uses shell command `xsel -o\' to paste from x-clipboard. With\none prefix arg, pastes from X-PRIMARY, and with two prefix args,\npastes from X-SECONDARY."\n  (interactive)\n  (if (display-graphic-p)\n    (clipboard-yank)\n   (let*\n     ((opt (prefix-numeric-value current-prefix-arg))\n      (opt (cond\n       ((=  1 opt) "b")\n       ((=  4 opt) "p")\n       ((= 16 opt) "s"))))\n    (insert (shell-command-to-string (concat "xsel -o -" opt))))))\n\n(global-set-key (kbd "C-c C-w") \'my-cut-to-xclipboard)\n(global-set-key (kbd "C-c M-w") \'my-copy-to-xclipboard)\n(global-set-key (kbd "C-c C-y") \'my-paste-from-xclipboard)\n</code></pre>\n'}, {'answer_id': 56587135, 'author': 'asmeurer', 'author_id': 161801, 'author_profile': 'https://Stackoverflow.com/users/161801', 'pm_score': 2, 'selected': False, 'text': '<p>I use the following, based on the other answers here, to make <code>C-x C-w</code> and <code>C-x C-y</code> be copy and paste on both Mac and Linux (if someone knows the version for Windows feel free to add it). Note that on Linux you will have to install xsel and xclip with your package manager.</p>\n\n<pre class="lang-lisp prettyprint-override"><code>;; Commands to interact with the clipboard\n\n(defun osx-copy (beg end)\n  (interactive "r")\n  (call-process-region beg end  "pbcopy"))\n\n(defun osx-paste ()\n  (interactive)\n  (if (region-active-p) (delete-region (region-beginning) (region-end)) nil)\n  (call-process "pbpaste" nil t nil))\n\n(defun linux-copy (beg end)\n  (interactive "r")\n  (call-process-region beg end  "xclip" nil nil nil "-selection" "c"))\n\n(defun linux-paste ()\n  (interactive)\n  (if (region-active-p) (delete-region (region-beginning) (region-end)) nil)\n  (call-process "xsel" nil t nil "-b"))\n\n(cond\n ((string-equal system-type "darwin") ; Mac OS X\n  (define-key global-map (kbd "C-x C-w") \'osx-copy)\n  (define-key global-map (kbd "C-x C-y") \'osx-paste))\n ((string-equal system-type "gnu/linux") ; linux\n  (define-key global-map (kbd "C-x C-w") \'linux-copy)\n  (define-key global-map (kbd "C-x C-y") \'linux-paste)))\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/64360', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8522/']