I am trying to set [Ctrl]-[;] as a keybinding in my .emacs like this
(global-set-key "\C-;" 'comment-or-uncomment-region)
however it doesn’t work when I try (i don’t get any error messages, it just has no effect). It will work though if i try a normal character (such as setting it to “\C-p”).
I have also tried
(global-set-key (kbd "C-;") 'comment-or-uncomment-region)
but I don’t like this option because for me it doesn’t work when i run “emacs -nw”. Any thoughts on how I can do this?
EDIT:
When I run C-hcC-; in emacs -nw I get the output:
; runs the command self-insert-command
which is exactly the same as when I run C-hc; in emacs -nw
So I believe phils is right, that it is a terminal problem, because emacs never actually sees C-;, it only sees ;
Using
(kbd "C-;")is absolutely fine and correct.I suspect when you type C-; when running
emacs -nw, your terminal is not actually sending anything to Emacs.So your problem is more likely to be a question of how to get your terminal to send C-; to Emacs (or alternatively how to get Emacs to recognise the sequence which is sent).
If you run
emacs -Q -nwand type C-hcC-;, do you get a"C-; is undefined"message?Assuming that it is a terminal issue, here are some related Q&As which may point you in the right direction, but it’s going to depend upon the particular terminal you are using.