开发者

Is there a quick way to unbind keys in Emacs?

开发者 https://www.devze.com 2023-04-07 04:24 出处:网络
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

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     bac开发者_如何转开发kward-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.


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消