5

I've become accustomed to using C-x p for switching to the previous window.

And, I recently had to start including a company-wide startup.el file that defines the prefix C-x p-. I don't use any of the C-x p- shortcuts.

Is there a way that I can undefine the C-x p- prefix after it's been defined?

4
  • 2
    Find out what keymap it is defined in, and then (define-key THAT-MAP "\C-xp" nil).
    – Drew
    Nov 18, 2014 at 20:30
  • emacs.stackexchange.com/questions/2150/… looks like it might be what you're looking for, but I'm not entirely sure. If it is, we can mark your question as a duplicate which helps consolidate answers and improves search results. Nov 18, 2014 at 20:41
  • 1
    What is the exact define-prefix-command call being used to define this prefix key? It would be helpful if you could give an example of what the prefix-key is and how it is being defined. The description here shows the prefix key being bound to a keymap. So, you would simply need to unset that keybinding.
    – Pradhan
    Nov 18, 2014 at 20:56
  • For example, with the default emacs configuration, (key-binding (kbd "C-x")) will say something like (keymap Control-X-prefix). To make C-x the prefix for your own set of bindings, you would simply rebind the key C-x to your keymap.
    – Pradhan
    Nov 18, 2014 at 20:59

3 Answers 3

6

I found a solution:

(global-unset-key (kbd "C-x p-"))

I can't find documentation of this anywhere, so I"m not sure if it works by coincidence or by design. However, the reproducible effect is that it disables the keymap and allows me to redefine "C-x p".

3
  • Did this solve your problem? Nov 19, 2014 at 23:24
  • 1
    "I found a solution" Nov 20, 2014 at 20:31
  • Then this is an answer. Nov 20, 2014 at 20:39
2

From gnu.org:

M-x local-unset-key <RET> key

Make key undefined locally (in the major mode now in effect).

So you can use

(local-unset-key (kbd "C-x p-"))
3
  • Nope. That doesn't work on prefixes. Thanks for the suggestion though. Nov 18, 2014 at 19:11
  • @Ken (local-unset-key (kbd "C-x p"))?
    – nicael
    Nov 18, 2014 at 19:20
  • 1
    @nicael but this would have to be done on every buffer, no?
    – Malabarba
    Nov 20, 2014 at 0:21
0

Following only work in emacs 25.3.1:

(local-unset-key (kbd "C-x p"))
1
  • Can you elaborate, including where to use that (local to what)?
    – Drew
    Jan 2, 2018 at 15:44

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.