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 ;
Indeed C-;
is typically not something your terminal is able to send to an underlying application like Emacs (so it works under a GUI but not in a terminal). But I wonder: why do you need such a binding anyway, given that M-;
is already bound to comment-dwim
which does comment/uncomment the region when the region is selected, so it provides a superset of comment-or-uncomment-region
.
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 -nw
and 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With