1

Here is one thing that has been hard to find out. In Spacemacs (or Emacs), is it possible to have a given key combination set to execute whatever another key combination is supposed to do?

In other words, is it possible, for example, to have the F5 key always execute whatever the combination C-c C-c is supposed to do? Something like:

(global-set-key [remap (kbd "F5")] (kbd "C-c C-c")) 

Let me give a concrete example for clarity. The key combination C-c C-c is often used to send the current buffer's entire code to interpreter/console, be it to send the buffer's code to the Python interpreter in case the code resides in a .pyfile, or to send it to a R console with package ESS in a .R file.

Now, suppose that one wants to have the F5 key set to do that for these two languages and maybe even more. One obvious solution would be to simply implement key bindings that are different for each package. However, it would be much easier if it was possible to simply say: whenever F5 is pressed, it should result in whatever command associated to `C-c C-c being called.

Is it possible to have such a thing? I am particularly interested in doing that for Spacemacs, but of course a more generic answer for Emacs is acceptable.

Louis15
  • 295
  • 3
  • 12

1 Answers1

1

Try

(define-key key-translation-map [f5] (kbd "C-c C-c"))

It should solve your problem.

campovski
  • 2,979
  • 19
  • 38
  • Almost perfect solution! The caveat is that, for some reason, it doe not work if the new key combination uses `super` or `hyper` keys. For instance: `(define-key key-translation-map [H-f5] (kbd "C-c C-c"))` – Louis15 Sep 04 '17 at 08:20
  • Are you sure you're spelling the key presses correctly? I always just do `C-h k ` and see what the help/mini buffer gives, then put that in `kbd`. E.g. use `(kdb "")` for `super-F5` (I can't give a hyper example because I don't have hyper). – jpkotta Sep 05 '17 at 20:36