Kenneth Yee
Kenneth Yee

Reputation: 11

How do I reset Emacs keybindings to default?

I was unsetting the C-z quit shortcut in my Emacs. I accidentally made a typo, and somehow made it so that I couldn't capitalize the letter C. In an effort to try to restore this, I accidentally unset C-y, and then accidentally set it back to "undo" instead of "paste". Then I accidentally unset the letter "c" completely.

My Emacs is in a mess right now. How can I just reset these keys to their default commands?

For reference, I am running on EC2 with AMI 5.10. I also could not find an existing Emacs init file in any of the standard locations.

Upvotes: 1

Views: 732

Answers (1)

phils
phils

Reputation: 73345

There's no "reset all the keys" command (and for numerous reasons it wouldn't make any sense to include one), but if you don't want to restart your existing instance, then do this:

  1. Start a new, separate instance.
  2. In that, ask Emacs what the key is bound to, using C-hk
  3. Back in the original instance, rebind the key to that command (in the same keymap)

For the global keymap you can use M-x global-set-key

More generally, evaluate the code (define-key KEYMAP (kbd "KEY SEQUENCE") #'COMMAND) for the KEYMAP name indicated in the *Help* buffer. E.g. if I saw:

C-y runs the command yank (found in global-map)

Then (because it's the global keymap) I could use either of these:

  • (define-key global-map (kbd "C-y") #'yank)
  • M-x global-set-key RET C-y yank RET

Upvotes: 1

Related Questions