1

I am trying to remap C-c, C-x, C-v (windows editing shortcuts for copy, cut, paste) using these 3 lines of elisp code:

(global-set-key (kbd "C-c") 'kill-ring-save)
(global-set-key (kbd "C-x") 'kill-region)
(global-set-key (kbd "C-v") 'yank)

kill-region and yank works well whereas the C-c binding does not. Can C-c be rebound? I prefer to set the keybindings myself instead of using cua-mode so that i can have finer control over it.

  • 1
    It depends on where and when you evaluate this code. Well actually, the important thing - that the code that is evaluated after the code you quoted does not set key binding to C-c *. Try to fully load emacs and then M-: <return> (global-set-key (kbd "C-c") 'kill-ring-save) <return>. And then try again. – d12frosted Jul 29 '15 at 11:38
3

As others have suggested, you'd be wise to avoid overwriting some of the most common keychord prefixes with your own keybindings.

Here's a stylized example of what's going to happen. Let's say we have a keychord prefix of C-c a that allows you to send messages to yourself based on what key comes next:

(global-set-key (kbd "C-c aa") (lambda () (interactive) (message "You pressed a")))
(global-set-key (kbd "C-c ab") (lambda () (interactive) (message "You pressed b")))

Now, when you press C-c aa, Emacs politely tells you that "You pressed a", and when you press C-c ab, it informs you that "You pressed b". Such functionality!

However, let's now say you clobber your prefix by assigning it directly to a command:

(global-set-key (kbd "C-c a") (lambda () (interactive) (message "I've clobbered your other bindings!")))

Now, you can no longer get to C-c aa to have Emacs tell you that "You pressed a", because the new binding short-circuits the whole affair at C-c a and tells you that "I've clobbered your other bindings!"

Now, to make matters worse, C-c and C-x are two of the most common prefixes in Emacs, so if you hijack them, you'll have to rebind a very large chunk of the Emacs defaults.

Out of the box, C-x has its own keymaps (in the plural!): ctl-x-map, ctl-x-4-map, and ctl-x-5-map. Further, a great many modes bind C-c ... to their core commands. C-c C-c, for example, is the conventional way for modes to say "do that main thing I do."

In other words: if you really want common user interface keybindings, just use cua-mode. The "finer control" you can get by hand-binding the keys will turn out to mean a massive rebinding undertaking on your part: yes, it will be finer control, but it's probably not worth your time.

  • thanks Dan,,, i think, i can live without windows shortcuts... – Madhavan Jul 29 '15 at 16:37
2

If you want more traditional key bindings better activate cua-mode. If you want to remap them manually, you will eventually get more problems than benefits, because key bindings like C-c are in fact prefixes for a lot of other key bindings, and not only built-in ones. So, if you remap these, you will need to remap a lot of stuff.

As an advice, don't do it. Learn Emacs way, or use Vi emulation (I'm not familiar with it, but I guess it's the only widely-used alternative). I myself don't use most standard key-bindings and I don't use vi-emulation either. You could end up with situation like this, but first ask yourself if you really want it and why.

  • 2
    +1. My personal opinion: As an advice, don't do it. Learn Emacs way. If you start using org-mode a lot, your C-c rebinds will come back to bite you. – Kaushal Modi Jul 29 '15 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.