It would be nice if I could paste a commands name into the helm minibuffer when I am using describe-function and find-function without typing. Additionally I need the possibility to exclude certain bindings from this feature, that I use from within helm buffers.

Edit: I've tried this command:

(defun my-insert-command-name-on-key (key) (interactive "kInsert function on key: ") (insert (symbol-name (key-binding key))))

But it doesn't work properly in helm buffers. Sometimes it pastes the name, but mostly it pastes "undefined".

  • I am not sure what you try to achive... You know that you can get a description by using C-h k followed by the key binding? Otherwise you may try emacs-helm/helm-descbinds - a helm frontend for describe-bindings. – theldoria Jul 13 '16 at 18:24
  • Didn't know describe-key. Thx. And the equivalent for find-function is find-function-on-key. But I would like to avoid additional bindings. Would it be possible for helm to check if the binding I am using is defined in helm keymap and if not, insert command's name ? – bertfred Jul 13 '16 at 19:45

You could use the command describe-key-briefly C-hc with a prefix arg C-u (which inserts the text into the current buffer instead of just printing it), followed by the key sequence you want to paste the name of the command you just typed.

For example, if you wanted to paste the command save-buffer you would type C-uC-hcC-xC-s which would insert C-x C-s runs the command save-buffer which is close, but not quite what you want since it has the extra text at the beginning that you'd have to delete.

I define the following function as advice to describe-key-briefly so that any time I invoke it, the name of the command automatically gets added to the kill-ring so I can just hit C-y to paste the last key that I described.

(defun describe-key-copy-as-kill (&optional key insert untranslated)
    (kill-new (format "%s" (key-binding key))))
(advice-add 'describe-key-briefly :after #'describe-key-copy-as-kill)
  • Good answer, but not quite what I'm looking for. Too many keystrokes. – bertfred Jul 15 '16 at 7:15

You can do it with a key macro.


  1. Start record key macro. start-kbd-macro
  2. Move top.
  3. Copy first word (which should be the command name)
  4. Press M-x. (or whatever the helm version of it)
  5. Paste, hit enter

then, save the key macro by

  1. M-x name-last-kbd-macro
  2. M-x insert-kbd-macro

Put the code in your emacs init.

You can now give it a keybinding too. e.g.

(global-set-key (kbd "<f1>") 'my-super-cmd)

I don't use helm, don't have it installed. But I tried the above, should work in general.

Your Answer

