I want to be able to automatically insert pre-defined strings when pressing a certain keybinding. Currently this is being done with the following code snippet:

;;;;; Personal keybindings                                                
(global-set-key [f6] "\autocite[--]{}")

The problem is, that this does not work (the one in the example). Instead, Emacs will tell me "After 0 kbd macro iterations: Quit" which does not show up, when just doing the string without the "\". So how could I fix this and enter pre-defined strings which include special character such as "\"?

1 Answer 1


You need to double backslashes within strings:

(global-set-key [f6] "\\autocite[--]{}")

A more reliable binding uses the insert function explicitly:

(global-set-key [f6] #'(lambda ()
                         (insert "\\autocite[--]{}")))

and you'll probably want to move point within the braces:

(global-set-key [f6] #'(lambda ()
                         (insert "\\autocite[--]{}")
                         (forward-char -1)))
  • @jch I would prefer defining the interactive function first and then binding a key to that function name. Commented Nov 1, 2015 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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