在 emacs 中定义键绑定
我想将 emacs 中的命令映射到键绑定。我希望命令 Control-l
与命令 Alt-x goto-line
后跟 return 具有相同的效果(因为该命令首先需要调用 return然后是行号)。
我按如下方式修改了 init 文件:
(define-key (Mx goto-line) '\Cl)
但这不起作用。错误是 define-key
被赋予了超过 1 个参数。
有谁知道如何重置 emacs 中的键绑定?
谢谢!
I'd like to map a command in emacs to a key-binding. I want the command Control-l
to have the same effect as the command Alt-x goto-line
followed by a return (since that command first needs a return to be invoked and then a line number).
I modified the init file as follows:
(define-key (M-x goto-line) '\C-l)
but that didn't work. The error was that define-key
was being given more than 1 arguments.
Does anyone know how to reset key-bindings in emacs?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Mg g 是
goto-line
的默认快捷方式。你可能想尝试一下。要重新定义 Cl 使用:
M-g g is the default shortcut for
goto-line
. You might want to try that.To redefine C-l use:
自定义大量按键绑定的最简单方法是安装 John Wiegley 的 bind-key 模块,该模块是 use-package 的一部分 Lisp 包。
init.el
中的解决方案:次要模式键通常会覆盖全局键,因此如果您不希望出现这种行为,请改用函数
bind-key*
。包在 MELPA 上,如果你不知道它是什么,快速了解Emacs 包管理(将 MELPA 设置为存储库需要 2 分钟)。Emacs 中键绑定的主要问题是次要模式键通常会覆盖您的自定义键。在普通 Emacs 中,人们通过为自己的键绑定创建次要模式来解决问题。如果您确实想了解 Emacs 键的工作原理,请阅读 按键绑定 @ Emacs 手册 和 键盘映射 @ Elisp 手册 仔细。
Easiest way to customize lots of keybindings is to install John Wiegley's bind-key module, which is a part of use-package Lisp package. Solution in your
init.el
:Minor modes keys usually override global keys, so if you don't want such behavior, use function
bind-key*
instead. The package is on MELPA, if you don't know what is it, quickly learn about Emacs package management (should take you 2 minutes to set up MELPA as your repository).The main problem with keybindings in Emacs is that minor modes keys often override your custom ones. In vanilla Emacs people workaround by creating a minor mode for your own keybindings. If you really wanna understand how Emacs keys work, read Key Bindings @ Emacs Manual and Keymaps @ Elisp Manual carefully.
我已设置为
(global-set-key (kbd "Cx g") 'goto-line)
。您可以使用它或(global-set-key (kbd "Cl") 'goto-line)
。我个人不会触及 Cl 键的默认行为。如果必须使用 Mx Define-key,请使用
(define-key global-map (kbd "Cl") 'goto-line).
Define-key 的第一个参数是一个 KEYMAP。I have set as
(global-set-key (kbd "C-x g") 'goto-line)
. You can use that or(global-set-key (kbd "C-l") 'goto-line)
. I would personally do not touch the C-l key from its default behavior.If you must use M-x define-key, use
(define-key global-map (kbd "C-l") 'goto-line).
The 1st argument to define-key is a KEYMAP.