i want a shortcut for the nice little function comment-or-uncomment-region
.
The thing is, it works fine for me in every mode using M-x comment-or-uncomment-region
. And espacially it works differently (#
for python and //
for C++) so everything is fine here.
But as i said i want a shortcut for this.
So i wrote the following in my init.el
file:
(global-set-key (kbd "C-;") 'comment-or-uncomment-region)
This now works for all my .cpp files, where I'm in c++-mode, but in python-mode it says, this function is not on a key. But i think its global-set, so what am I doing wrong? Or are some other functions able to unset the key (maybe in the initialization) ?
emacs -Q
(no init file), would help answering.python-mode
is probably binding its own command to the key in its keymap. Try binding the key topython-mode-map
inpython-mode-hook
or using something likeeval-after-load
.(add-hook 'python-mode-hook (local-set-key (kbd "C-;") 'comment-or-uncomment-region))' and '(add-hook 'python-mode-hook (setq comment-start "#"))
it works. Im sure this isnt the cleanest way, but it works ! Thank you for that hint! @DoMiNeLa10comment-dwim
? I think it is bound by default toM-;
add-hook
takes a function as the argument.