I recently installed Emacs 24 on my Ubuntu machine. I access this machine via SSH from a Mac. I am trying to search for some text and I am pasting the text in the search command's buffer. I.e I do C-s, then paste by doing ⌘+v on my mac keyboard.

The text gets pasted into the document instead of the search command's buffer.This wasn't the case with Emacs23 where the pasted text was in the search command and not in the document.

How do I get ⌘+v to paste text into the search buffer?

  • Does a regular C-y not work? It works for me. – PythonNut Jan 23 '15 at 21:52
  • If C-y does not work, but it works if you start Emacs using emacs -Q, then recursively bisect your init file to find the culprit. You can use command comment-region to comment out a region of text (C-u to uncomment a region). Do that to narrow down your init file to 1/2 of it, then 1/4, 1/8, 1/16,... – Drew Jan 23 '15 at 23:55
  • @Drew, C-y and ⌘+v do not run the same command in isearch-mode, in fact, C-y does not even run yank, the problem lies in the function xterm-paste (I think) – Jordon Biondo Jan 24 '15 at 0:03

It is most likely that for you ⌘+v is interpretted as which runs the function xterm-paste. this function gets the text from your clipboard and then runs yank to insert it, however, in isearch-mode the normal yank keybinding actually runs a special command to yank into the isearch minibuffer instead of the current buffer.

My guess is that in the past, the minibuffer was actually active when isearching, and now it is not. I advised xterm-paste so them when run in isearch-mode it will act in a special way that works with isearch instead of just yanking.

(defadvice xterm-paste (around support-isearch-mode activate)
  (if isearch-mode
      ;; when isearch-mode, act special.
      (let* ((end-marker-length (length xterm-paste-ending-sequence))
             (pasted-text (with-temp-buffer
                            (set-buffer-multibyte nil)
                            (while (not (search-backward
                                         (- (point) end-marker-length) t))
                              (let ((event (read-event
                                            nil nil
                                            ;; Use finite timeout to avoid                                                                                                                                                                                                                                                     
                                            ;; glomming the event onto                                                                                                                                                                                                                                                         
                                            ;; this-command-keys.                                                                                                                                                                                                                                                              
                                (when (eql event ?\r)
                                  (setf event ?\n))
                                (insert event)))
                            (let ((last-coding-system-used))
                               (point-min) (point)
                               (keyboard-coding-system) t)))))
        ;; then only real change
        (isearch-yank-string pasted-text))

Look at the code from xterm-paste and you'll see that the special case in this adivce is just the copy and pasted code, expect yank has been changed to (isearch-yank-string pasted-text))

| improve this answer | |
  • So do I change it back to yank ? – Bharat Jan 25 '15 at 0:24
  • No, you just need to evaluate the code in the answer and normal OSX pasting should work. – Jordon Biondo Jan 25 '15 at 18:30
  • When I eval the above region in Emacs 24.5, it does not cause ⌘+v to start working. Using C-y works, so maybe mapping ⌘+v to whatever C-y is mapped to is the solution. – Kevin Jun 1 '15 at 13:36

In emacs, the keybindings for cut-and-paste are very different. This is an unfortunate fact, and it is very difficult to change. Anyway, it goes like this:

  • C-y to "paste" (called yank in Emacs)
  • M-w to "copy" (called kill-ring-save in Emacs)
  • C-w to "cut" (called kill-region in Emacs)

Emacs has these commands because it existed long before C-v paste, C-c copy, and C-x cut became the norm. Emacs also has its own "clipboard" (called the kill-ring) which stores the things you cut.

| improve this answer | |
  • Thanks, these work in the main buffer of the document but in the search command's buffer(minibuffer). I.e the place where I enter the search term after I do C-s. – Bharat Jan 23 '15 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.