如何在不更改 TAB 的情况下将命令绑定到 C-i? [英] How do I bind a command to C-i without changing TAB?

查看:11
本文介绍了如何在不更改 TAB 的情况下将命令绑定到 C-i?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 emacs 中,我想将命令绑定到 C-i.所以我把 (global-set-key "C-i" 'forward-word)

In emacs, I want to bind a command to C-i. So I put (global-set-key "C-i" 'forward-word)

在我的 .emacs 文件中.这有效,除了现在 TAB 键也绑定到 'forward-word .

in my .emacs file. This works, except now the TAB key is bound to 'forward-word as well.

如何在不更改 TAB 的情况下将命令绑定到 C-i?

推荐答案

简而言之,这应该可以为您解决问题:

In short, this should solve the problem for you:

(setq local-function-key-map (delq '(kp-tab . [9]) local-function-key-map))
(global-set-key (kbd "C-i") 'forward-word)

更长的版本:

来自关于 功能键:

在ASCII中,C-i和是一样的特点.如果终端可以区分它们,Emacs传达了对 Lisp 的区别通过将前者表示为整数 9,后者作为符号选项卡.

In ASCII, C-i and <TAB> are the same character. If the terminal can distinguish between them, Emacs conveys the distinction to Lisp programs by representing the former as the integer 9, and the latter as the symbol tab.

大多数时候,它没有用区分两者.所以通常本地功能键映射(见Translation Keymaps) 设置为映射tab 进入 9. 因此,一个键绑定字符代码 9(字符 C-i)也适用于选项卡.同样对于该组中的其他符号.这函数 read-char 同样转换将这些事件转化为字符.

Most of the time, it's not useful to distinguish the two. So normally local-function-key-map (see Translation Keymaps) is set up to map tab into 9. Thus, a key binding for character code 9 (the character C-i) also applies to tab. Likewise for the other symbols in this group. The function read-char likewise converts these events into characters.

因此,一旦您执行以下操作,您就可以看到键绑定的不同之处:

So, once you do the following, you can see the difference in the key bindings:

(setq local-function-key-map (delq '(kp-tab . [9]) local-function-key-map))

;; this is C-i
(global-set-key (kbd "C-i") (lambda () (interactive) (message "C-i"))) 
;; this is <tab> key
(global-set-key (kbd "<tab>") (lambda () (interactive) (message "<tab>")))

请注意,每种模式对各种 TAB 绑定的设置都不同,因此您可能需要针对您关心的每种模式进行自定义.

Note, each mode sets up the various TAB bindings differently, so you may need to do customization per mode that you care about.

版本依赖:

以上适用于 Emacs 23.1.来自新闻文件:

The above works for Emacs 23.1. From the NEWS file:

功能键序列现在使用`local-function-key-map'映射,一个新变量.这继承自全局变量 function-key-map,不再直接使用.

Function key sequences are now mapped using `local-function-key-map', a new variable. This inherits from the global variable function-key-map, which is not used directly any more.

这意味着,在 22 及更早版本中,您可以通过使用变量 function-key-map 获得相同的效果.我对此进行了测试,发现它适用于 Emacs 21.

Which means, in versions 22 and earlier, you can get the same effect by using the variable function-key-map. I tested this and found it to work with Emacs 21.

(setq local-function-key-map (delq '(kp-tab . [9]) function-key-map))
(global-set-key (kbd "C-i") 'forward-word)

这篇关于如何在不更改 TAB 的情况下将命令绑定到 C-i?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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