I've written a regular expression to transform Markdown links into Org Mode links and I've stored it into a variable.

(defvar markdown-link-to-org-regexp "s/\[\(.+\)\](\(.+\))/[[\2][\1]]")

I'm using Doom and Evil mode so next time I type : so I go to the minibuffer I'd like to bring that string into the minibuffer. Is there an easy way to do it?

  • Copy the region and then yank it (C-y) into the minibuffer?
    – NickD
    Oct 6, 2020 at 18:06
  • The region as plain text won't be available when I need it. That regex will live in init.el and the usage will happen when editing some org file and pasting some content from the internet. So the request is to bring to the minibuffer a predefined string from a variable. Oct 7, 2020 at 6:32
  • Note that you need to quote all the backslashes. Maybe, that is the actual problem. The right expression would be: (defvar markdown-link-to-org-regexp "s/\\[\\(.+\\)\\](\\(.+\\))/[[\\2][\\1]]").
    – Tobias
    Dec 2, 2021 at 18:24

2 Answers 2


Define an interactive function (aka command), which inserts this string. Then put this function on a key binding.

(defun my-insert-regex ()
  (insert (format "%S" markdown-link-to-org-regexp)))

(define-key global-map (kbd "C-c i") #'my-insert-regex)

When doing M-: you then just have to press C-c i to insert this string at the prompt.

Note, that your regex is eventualy wrong and needs more escape characters. re-builder can help you construct this regex.

Second option:

This M-: promt normaly supports a history. You just need to type or paste it once, then you can retrieve former inputs with <up> and <down> keys. C-r searches backwards in the history. (C-r maybe has a different keybinding in Doom, Evil).


I don't understand your use case. You can copy text and paste (yank) text into the minibuffer, as @NickD pointed out in a comment. If the text isn't in the kill ring, but is actually stored in a file, then you don't need to invoke the minibuffer to run it. You can wrap it in a function and run it directly:

(defun my-regex-set ()
  (defvar markdown-link-to-org-regexp "s/\[\(.+\)\](\(.+\))/[[\2][\1]]"))

With this function defined, you can call it with M-x my-regex-set, or you can bind it to a key combo.

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.