在 emacs 中取消设置键绑定 [英] Unset key binding in emacs

查看:24
本文介绍了在 emacs 中取消设置键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在 zen-coding 的代码中,C-j"掩盖了C-j"的正常行为(newline-and-indent)

For example, in the codes of zen-coding, the "C-j" shadows the normal behavior of "C-j" (newline-and-indent)

(define-key zencoding-mode-keymap (kbd "C-j") 'zencoding-expand-line)

那我怎样才能取消这个键绑定并再次使用C-j作为newline-and-indent?

Then how can I unset this keybinding and use C-j for newline-and-indent again?

我试过了,但没有用:

(add-hook 'html-mode-hook
          (lambda ()
            (progn
              (zencoding-mode)
              (local-set-key (kbd "C-j") 'newline-and-indent))))

有人对此有什么想法吗?

Does anyone have ideas about this?

推荐答案

解除键绑定(对于任何键映射)的一般方法是定义一个 nil 的绑定:

The general way to unbind a key (for any keymap) is to define a binding of nil:

(define-key KEYMAP KEY nil)

为了方便起见,还有两个标准函数用于从全局键盘映射和本地键盘映射(通常是主模式的键盘映射)解除绑定.

For convenience, there are also two standard functions for unbinding from the global keymap and from the local keymap (which is usually the major mode's keymap).

  • (global-unset-key KEY)
  • (local-unset-key KEY)

那些是交互式命令,根据它们各自的补充global-set-keylocal-set-key.

Those ones are interactive commands, as per their respective complements global-set-key and local-set-key.

至于您的具体示例,您可能想要这样的东西:

As to your specific example, you probably want something like this:

(eval-after-load "zencoding-mode"
  '(define-key zencoding-mode-keymap (kbd "C-j") nil))

这篇关于在 emacs 中取消设置键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆