Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm copying text from either Google Chrome or PDFs, and pasting into Emacs.

The original text has smart quotes. I don't want smart quotes in the output.

Is there a way, either on the Copying side or on the Pasting side, to automatically strip out the smart quotes?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

How about:

(defun replace-smart-quotes (beg end)
  "Replace 'smart quotes' in buffer or region with ascii quotes."
  (interactive "r")
  (format-replace-strings '(("\x201C" . "\"")
                            ("\x201D" . "\"")
                            ("\x2018" . "'")
                            ("\x2019" . "'"))
                          nil beg end))

Put that in your ~/.emacs and you should be able to use M-x replace-smart-quotes to fix all quotes in the current buffer or selected region.

To avoid restarting Emacs for the ~/.emacs change to take effect, move your cursor to the end of the defun with M-C-e and evaluate it C-x C-e.

Update re comment:

To automatically do this when yanking (pasting), you could do something like the following:

(defun yank-and-replace-smart-quotes ()
  "Yank (paste) and replace smart quotes from the source with ascii quotes."
  (replace-smart-quotes (mark) (point)))

If you then want to do that when you hit C-y, you can bind it using:

(global-set-key (kbd "C-y") 'yank-and-replace-smart-quotes)

It's probably a better idea to use another key however (maybe C-c y) as this will use some of the default yank functionality.

share|improve this answer
Thanks. But what about a function that will strip the quotes out during copy/paste? Kind of like "Paste and Match Formatting" with stripping out smart quotes. –  Peter Salazar Jun 12 '13 at 8:15
You can do that too, I've added an example. Don't forget to accept the answer if it solves your problem. –  Tom Jun 13 '13 at 23:45
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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