Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a quick way to unbind keys in Emacs?

Tags:

emacs

I did a ctrl h b to view all my bindings in emacs. Now I want to unbind a lot of keys, simply because I never use those functions of Emacs and I don't want to perform them when I accidently press the bound keys! This also frees up a lot of keys for other tasks (for use with Cedet for example). So apart from global-unset-key, is there any method to remove bindings in bulk?

 C-a     move-beginning-of-line C-b     backward-char C-c     mode-specific-command-prefix C-d     delete-char C-e     move-end-of-line C-f     forward-char C-g     keyboard-quit C-h     help-command C-k     kill-line C-l     recenter-top-bottom C-n     next-line C-o     open-line C-p     previous-line C-q     quoted-insert C-t     transpose-chars C-u     universal-argument C-v     scroll-up C-x     Control-X-prefix C-z     suspend-frame ESC     ESC-prefix 

I want to remove most of these bindings which are absolutely useless for me.

like image 483
AnkurVj Avatar asked Sep 25 '11 23:09

AnkurVj


People also ask

How do you unbind keys?

In the search box, type Device Manager, and press Enter. Find the device that you need to uninstall from the list. Right-click and click Uninstall. A device removal confirmation will appear, click Ok.

How do I set keyboard shortcuts in Emacs?

emacs file. To interactively bind keys for all modes, type M-x global-set-key RET key cmd RET . To bind a key just in the current major mode, type M-x local-set-key RET key cmd RET . See Key Bindings in The GNU Emacs Manual .

How do you unbind a key in Quake?

Should also be able to change it via console (press the ~ key and then type in the bind t "messagemode" command, changing the t before hitting submit. Alternatively, if you just don't want it to be bound at all, type unbind t via console and it should unbind it.

How do you unbind in F1 console?

Or sign in with one of these services How do I unbind a key? To remove default Rust controls, press ESC, select Options and then choose Controls. To remove a custom keybind, press F1 and type bind <key> "".


2 Answers

There's no built-in way to unset a lot of keys, because it's easy to do it yourself:

(Edited for strict correctness:)

(dolist (key '("\C-a" "\C-b" "\C-c" "\C-d" "\C-e" "\C-f" "\C-g"                "\C-h" "\C-k" "\C-l" "\C-n" "\C-o" "\C-p" "\C-q"                "\C-t" "\C-u" "\C-v" "\C-x" "\C-z" "\e"))   (global-unset-key key)) 

Although I have to say that most of the commands you call "useless" I would call "essential."

(Edited to add:)

As for freeing up keys for other tasks, there's plenty of unused key real estate:

  • Key sequences consisting of C-c followed by a letter are by convention reserved for users.
  • If you have an extra modifier available, like Option on the Mac or the Windows key on a PC, you can associate it with an Emacs modifier like super. I have super-b bound to browse-url-at-point, for example.
  • If you're not on a plain terminal, the shift key becomes available to distinguish key sequences. For example, I have shift-meta-b bound to bury-buffer.
  • For commands that are useful but not run often enough to warrant a dedicated key sequence, you can use defalias to provide a shorter name. In my .emacs file, I have (defalias 'ru 'rename-uniquely) and (defalias 'c 'calendar) (among many others).
like image 54
Sean Avatar answered Sep 22 '22 19:09

Sean


global-unset-key and local-unset-key are useful, but it's worth having an answer to this question that points out that the general way to unbind a key (for any keymap) is to define a binding of nil:

(define-key KEYMAP KEY nil) 

If you follow the code for either of those other functions, you'll notice that this is exactly what they do.

like image 22
phils Avatar answered Sep 20 '22 19:09

phils