Bind command to C-RET in Emacs

Let's say I have some interactive function in Emacs my-function , how can I bind it to Ctrl + RET?

I tried with:

 (global-set-key (kbd "C-RET") 'my-function) 

and

 (global-set-key (kbd "C-return") 'my-function) 

but none of them seem to work. is it even possible?

+6
source share
2 answers

Always remember that kbd very conveniently accepts the same syntax that Emacs gives you when you ask it about a key sequence, so you never have to guess.

Ch k C-RET tells me:

 <C-return> 

so I would use (kbd "<C-return>")

OTOH, when running Emacs in my terminal, Ch k C-RET tells me:

 Cj 

because C-RET not a valid control character in the terminal, and therefore Emacs does not receive the same input that it receives in GUI mode (so I could not use this binding in my terminal).

+15
source

This should work:

 (global-set-key [(control return)] 'my-function) 

It works for me, but may not be in the terminal, like @phils answer.

+1
source

All Articles