I want certain keys and key combinations to behave as other keys or key combinations in Emacs. For example, I want F5 to behave as a substitute for C-c for every possible combination involving it, or C-S- as C-. Is it possible to do that without manually rebinding all such key combinations?
To reassign a keyConnect the keyboard that you want to configure. Select the Start button, and then select Microsoft Mouse and Keyboard Center. From the displayed list of key names, select the key that you want to reassign. In the command list of the key that you want to reassign, select a command.
Find the key you want to be the new input and select it.Once you've chosen your key input and output, click on "Remap Key". If you want to change several keys, do this for the rest of the keys you want to change before moving onto the next step.
You can change the action that modifier keys, such as Control or Option, perform when you press them. On your Mac, choose Apple menu > System Settings, then click Keyboard in the sidebar. (You may need to scroll down.) Click Keyboard Shortcuts on the right, then select Modifier Keys in the list on the left.
The keys you are referring to are known as 'prefix keys'. A prefix key has its own keymap, so to make another key behave the same, you need to assign it to the same keymap. For control-c, you use the mode-specific-map
:
(global-set-key (kbd "<f5>") mode-specific-map)
Control on its own isn't a prefix key, or really a key at all, since it doesn't send a keypress to Emacs[1] until you hit another key. I'm not sure how to remap C-S- to C- within Emacs. You could do it system-wide with xmodmap, but that's probably not what you want.
[1] the control key (and shift, alt) do send a keypress to the operating system, but Emacs doesn't 'see' this unless there's another key pressed at the same time
I prefer
(define-key key-translation-map [f5] (kbd "\C-c"))
Here is a good resource.
To summarize the link given above: The disadvantage of global-set-key is that, when you define a key combination to enter a symbol, it doesn't work in isearch.
key-translation-map also has a problem. Imagine you defined a symbol | to execute a command and C-| to enter the symbol |, pressing C-| will execute the command.
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