给定emacs命令名称,您如何找到键绑定? (反之亦然)

时间:2021-01-31 18:17:18

If I know an emacs command name, says, "goto-line"; what if I want to query whether if there are any key-sequences bound to this command ?

如果我知道一个emacs命令名称,说“goto-line”;如果我想查询是否有任何键序列绑定到此命令,该怎么办?

And vice versa, given a key sequence, how can I find its command name ?

反之亦然,给定一个键序列,我该如何找到它的命令名?

4 个解决方案

#1


To just find key bindings for a command, you can use emacs help's "where-is" feature

要查找命令的键绑定,可以使用emacs help的“where-is”功能

C-h w command-name

If multiple bindings are set for the command they will all be listed.

如果为命令设置了多个绑定,则将全部列出。

For the inverse, given a key sequence, you can type

对于反向,给定一个键序列,您可以键入

C-h k key-sequence

To get the command that would run.

获取将运行的命令。

You can get detailed information about a command, also any non-interactive function defined, by typing

您可以通过键入获得有关命令的详细信息,以及定义的任何非交互式功能

C-h f function-name

Which will give you detailed information about a function, including any key bindings for it.

这将为您提供有关函数的详细信息,包括其中的任何键绑定。

C-h f variable-name

Key-maps are kept in variables, however the key codes are stored in a raw format. Try C-h v isearch-mode-map for an example.

键映射保存在变量中,但键代码以原始格式存储。尝试使用C-h v isearch-mode-map作为示例。

For more help on getting help, you can type

有关获得帮助的更多帮助,您可以输入

C-h ?

#2


C-h w (or F1-w): where-is RET somecommandname RET

C-h w(或F1-w):where-is RET somecommandname RET

Does just what you're asking - lists bound keys with no additional information. :)

只是你要问的是 - 列出没有附加信息的绑定密钥。 :)

#3


For interactively getting the command bound to a keyboard shortcut (or a key sequence in Emacs terms), see the selected answer.

要以交互方式获取绑定到键盘快捷键(或Emacs术语中的键序列)的命令,请参阅所选答案。

For programmatically getting the command bound to a given key sequence, use the function key-binding or lookup-key that takes a key sequence and returns its bound command. The function key-binding is what C-h k uses.

要以编程方式获取绑定到给定键序列的命令,请使用带有键序列的函数key-binding或lookup-key并返回其绑定命令。功能键绑定是C-h k使用的。

(key-binding (kbd "C-h m"))

returns the command bound to C-h m by searching in all current keymaps. The function lookup-key searches in a single keymap:

通过搜索所有当前键盘映射返回绑定到C-h m的命令。函数lookup-key在单个键映射中搜索:

(lookup-key (current-global-map) (kbd "TAB")) ; => indent-for-tab-command
(lookup-key org-mode-map (kbd "TAB")) ; => org-cycle
(lookup-key text-mode-map (kbd "TAB")) ; => nil
(lookup-key isearch-mode-map (kbd "TAB")) ; => isearch-printing-char

For programmatically getting all key sequences bound to a given command, where-is-internal is probably the function to use. The name of the function ending with internal seems to suggest that it's not for Emacs users to use in their init files but this function having a docstring seems to suggest otherwise. Anyone considering use of where-is-internal should first check if remapping keys instead can achieve their goal.

为了以编程方式获取绑定到给定命令的所有键序列,where-is-internal可能是要使用的函数。以internal结尾的函数的名称似乎暗示它不是Emacs用户在其init文件中使用的,但是这个具有docstring的函数似乎暗示了其他方式。任何考虑使用where-is-internal的人都应首先检查重新映射密钥是否可以实现其目标。

#4


An old question, but for the benefit of new readers, there are some other nice ways to see key bindings

一个老问题,但为了新读者的利益,还有一些其他很好的方法来查看键绑定

M-x describe-bindings

Lists all the bindings currently available, use isearch, occur, etc. to make good use of this list.

列出当前可用的所有绑定,使用isearch,occurrence等,以充分利用此列表。

M-x describe-prefix-map

This shows all the bindings available from the current mode, you can use the display buffer as you would any other readonly Emacs buffer, for example you can search freely for strings etc.

这显示了当前模式下可用的所有绑定,您可以像使用任何其他只读Emacs缓冲区一样使用显示缓冲区,例如,您可以*搜索字符串等。

M-x describe-mode

As well as giving you general info about the current mode, it will also list all the key bindings available.

除了提供有关当前模式的一般信息外,它还将列出所有可用的键绑定。

M-x describe-minor-mode

You will be prompted to enter the name of a minor mode, and then be shown info and key bindings for that minor mode.

系统将提示您输入次要模式的名称,然后显示该次要模式的信息和键绑定。

NOTE : The examples below use additional packages (available from MELPA)

注意:以下示例使用其他软件包(可从MELPA获得)

Which key

This shows you bindings just before you need them. Enter a prefix, for example C-x or C-c and a list of the bindings available in that prefix will be shown.

这会在您需要之前显示绑定。输入前缀,例如C-x或C-c,将显示该前缀中可用的绑定列表。

You can also view a list of key bindings available from the current mode by using:

您还可以使用以下方法查看当前模式下可用的键绑定列表:

M-x which-key-show-top-level

It is useful to bind which-key-show-top-level to a key chord of your choice, so you can view the keys available from anywhere.

将where-key-show-top-level绑定到您选择的键和弦是很有用的,这样您就可以从任何地方查看可用的键。

For example, C-s (isearch-forward) has an extensive key map which often unknown. e.g. M-s o starts occur using the current search string, I didn't know about this for many many years of using Emacs. Having which-key around has helped me discover many rare gems in Emacs.

例如,C-s(isearch-forward)有一个广泛的键映射,通常是未知的。例如M-s o开始使用当前搜索字符串,我在使用Emacs很多年后都不知道这个。拥有哪些关键帮助我在Emacs中发现了许多稀有宝石。

https://github.com/justbur/emacs-which-key

Guide key

Guide key works in much the same way as which-key I'd recommend taking a look at it to compare features.

引导键的工作方式与我建议使用哪种键来比较功能的方式非常相似。

https://github.com/kai2nenobu/guide-key

#1


To just find key bindings for a command, you can use emacs help's "where-is" feature

要查找命令的键绑定,可以使用emacs help的“where-is”功能

C-h w command-name

If multiple bindings are set for the command they will all be listed.

如果为命令设置了多个绑定,则将全部列出。

For the inverse, given a key sequence, you can type

对于反向,给定一个键序列,您可以键入

C-h k key-sequence

To get the command that would run.

获取将运行的命令。

You can get detailed information about a command, also any non-interactive function defined, by typing

您可以通过键入获得有关命令的详细信息,以及定义的任何非交互式功能

C-h f function-name

Which will give you detailed information about a function, including any key bindings for it.

这将为您提供有关函数的详细信息,包括其中的任何键绑定。

C-h f variable-name

Key-maps are kept in variables, however the key codes are stored in a raw format. Try C-h v isearch-mode-map for an example.

键映射保存在变量中,但键代码以原始格式存储。尝试使用C-h v isearch-mode-map作为示例。

For more help on getting help, you can type

有关获得帮助的更多帮助,您可以输入

C-h ?

#2


C-h w (or F1-w): where-is RET somecommandname RET

C-h w(或F1-w):where-is RET somecommandname RET

Does just what you're asking - lists bound keys with no additional information. :)

只是你要问的是 - 列出没有附加信息的绑定密钥。 :)

#3


For interactively getting the command bound to a keyboard shortcut (or a key sequence in Emacs terms), see the selected answer.

要以交互方式获取绑定到键盘快捷键(或Emacs术语中的键序列)的命令,请参阅所选答案。

For programmatically getting the command bound to a given key sequence, use the function key-binding or lookup-key that takes a key sequence and returns its bound command. The function key-binding is what C-h k uses.

要以编程方式获取绑定到给定键序列的命令,请使用带有键序列的函数key-binding或lookup-key并返回其绑定命令。功能键绑定是C-h k使用的。

(key-binding (kbd "C-h m"))

returns the command bound to C-h m by searching in all current keymaps. The function lookup-key searches in a single keymap:

通过搜索所有当前键盘映射返回绑定到C-h m的命令。函数lookup-key在单个键映射中搜索:

(lookup-key (current-global-map) (kbd "TAB")) ; => indent-for-tab-command
(lookup-key org-mode-map (kbd "TAB")) ; => org-cycle
(lookup-key text-mode-map (kbd "TAB")) ; => nil
(lookup-key isearch-mode-map (kbd "TAB")) ; => isearch-printing-char

For programmatically getting all key sequences bound to a given command, where-is-internal is probably the function to use. The name of the function ending with internal seems to suggest that it's not for Emacs users to use in their init files but this function having a docstring seems to suggest otherwise. Anyone considering use of where-is-internal should first check if remapping keys instead can achieve their goal.

为了以编程方式获取绑定到给定命令的所有键序列,where-is-internal可能是要使用的函数。以internal结尾的函数的名称似乎暗示它不是Emacs用户在其init文件中使用的,但是这个具有docstring的函数似乎暗示了其他方式。任何考虑使用where-is-internal的人都应首先检查重新映射密钥是否可以实现其目标。

#4


An old question, but for the benefit of new readers, there are some other nice ways to see key bindings

一个老问题,但为了新读者的利益,还有一些其他很好的方法来查看键绑定

M-x describe-bindings

Lists all the bindings currently available, use isearch, occur, etc. to make good use of this list.

列出当前可用的所有绑定,使用isearch,occurrence等,以充分利用此列表。

M-x describe-prefix-map

This shows all the bindings available from the current mode, you can use the display buffer as you would any other readonly Emacs buffer, for example you can search freely for strings etc.

这显示了当前模式下可用的所有绑定,您可以像使用任何其他只读Emacs缓冲区一样使用显示缓冲区,例如,您可以*搜索字符串等。

M-x describe-mode

As well as giving you general info about the current mode, it will also list all the key bindings available.

除了提供有关当前模式的一般信息外,它还将列出所有可用的键绑定。

M-x describe-minor-mode

You will be prompted to enter the name of a minor mode, and then be shown info and key bindings for that minor mode.

系统将提示您输入次要模式的名称,然后显示该次要模式的信息和键绑定。

NOTE : The examples below use additional packages (available from MELPA)

注意:以下示例使用其他软件包(可从MELPA获得)

Which key

This shows you bindings just before you need them. Enter a prefix, for example C-x or C-c and a list of the bindings available in that prefix will be shown.

这会在您需要之前显示绑定。输入前缀,例如C-x或C-c,将显示该前缀中可用的绑定列表。

You can also view a list of key bindings available from the current mode by using:

您还可以使用以下方法查看当前模式下可用的键绑定列表:

M-x which-key-show-top-level

It is useful to bind which-key-show-top-level to a key chord of your choice, so you can view the keys available from anywhere.

将where-key-show-top-level绑定到您选择的键和弦是很有用的,这样您就可以从任何地方查看可用的键。

For example, C-s (isearch-forward) has an extensive key map which often unknown. e.g. M-s o starts occur using the current search string, I didn't know about this for many many years of using Emacs. Having which-key around has helped me discover many rare gems in Emacs.

例如,C-s(isearch-forward)有一个广泛的键映射,通常是未知的。例如M-s o开始使用当前搜索字符串,我在使用Emacs很多年后都不知道这个。拥有哪些关键帮助我在Emacs中发现了许多稀有宝石。

https://github.com/justbur/emacs-which-key

Guide key

Guide key works in much the same way as which-key I'd recommend taking a look at it to compare features.

引导键的工作方式与我建议使用哪种键来比较功能的方式非常相似。

https://github.com/kai2nenobu/guide-key