在vim中映射数字键盘按键

发布于 2024-12-03 11:57:35 字数 339 浏览 1 评论 0原文

我无法让此映射在 xterm 终端内的 vim 中工作。

:map <k0> :echo 'Hello'<CR>

我可以得到相同的映射在 gvim 中正常工作。如果我在终端上的 vim 中发出上述命令,它会接受它,并且当我输入 :map 时它会正确显示。但在正常模式下,如果我按 0 键盘键,状态行上会显示“0”,然后在下一次按键时消失。

我正在使用 Fedora 14 附带的 vim(如果有的话)和普通的 xterm。键盘按键在插入模式下工作正常,无论数字锁定打开还是关闭。

我缺少什么?

I'm unable to get this mapping to work in vim inside an xterm terminal.

:map <k0> :echo 'Hello'<CR>

I can get the same mapping to work fine in gvim. If I issue the above command in vim on a terminal, it accepts it, and it shows up correctly when I type :map. But in normal mode, if I press the 0 keypad key, a "0" shows up on the status line, and then disappears with the next keypress.

I'm using the vim that came with Fedora 14 if that matters, and a plain xterm. The keypad keys work fine in insert mode, both with numlock on and off.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

豆芽 2024-12-10 11:57:35

尝试将此行添加到您的 ~/.Xdefaults:

xterm*appkeypadDefault: false

并重新启动 xterm。

“应用程序键盘模式”可能是您遇到麻烦的原因。

但我认为你不应该做你正在做的事情。在 --NORMAL-- 模式下,数字输入用于指示“计数”,如 4dd 中那样。将数字映射到其他命令很快就会给你带来麻烦。

您应该在问题中添加 xterm 标签。

Try to add this line to your ~/.Xdefaults:

xterm*appkeypadDefault: false

and relaunch xterm.

The "Application Keypad Mode" is likely the reason of your troubles.

But I don't think you should do what you are doing. In --NORMAL-- mode, numeric input is used to indicate "count" like in 4dd. Mapping numbers to other commands is going to get you into troubles fast.

You should add a xterm tag to your question.

番薯 2024-12-10 11:57:35

问题中有一些含糊之处,这可能表明了实际的问题。 vim 接受 k0 的绑定,假设它是一个功能键。

您会看到的大多数键盘都是从 1 开始的数字功能键,并且一些终端描述将功能键 1 等同于 k0,很少有人将其 k0 等同于功能键 10。也有可能有人认为它是数字键盘的一部分,但可能性不大(因为键盘使用的字符序列与键盘使用的字符序列不同)。功能键)。

假设您使用了了解功能键的终端描述。 vt100 终端描述不会这样做,因为 vt100 没有功能键(PF1PF4 除外,这取决于您与谁交谈)。但是,如果您有TERM=vt100,那么可以根据终端描述识别数字键盘的一些(例如,参见vt100+fnkeys 说明)。

然而,它不在TERM=xterm 中。

您忽略的是 vim (也许有帮助)使用其内置 termcap 修改终端描述。它使用如下表条目来识别 PF1 等:

{K_XF1,             IF_EB("\033O*P", ESC_STR "O*P")},
{K_XF2,             IF_EB("\033O*Q", ESC_STR "O*Q")},
{K_XF3,             IF_EB("\033O*R", ESC_STR "O*R")},
{K_XF4,             IF_EB("\033O*S", ESC_STR "O*S")},

但是没有编号键的条目; 0 键没有 "\033O*p"

如果 vim (在终端描述中)有 k0,并且您没有将其映射到任何内容,vim 会将其视为文字 0k1 等也会发生同样的情况,实际上将功能键和数字键盘视为同一事物。

就其价值而言,GNU screen 可以做同样的事情,而且还可以用于数字键。如果我在 screen 内运行 vimvim 将只看到 0。 vim 中的文字 0 在命令模式下没有多大作用。

There's some ambiguity in the question, which may indicate the actual problem. vim accepts that binding for k0 supposing that it is a function key.

Most keyboards that you'll see number function-keys starting at 1, and a few terminal descriptions equate function-key 1 to k0, a few equate it k0 to function-key 10. It's also possible that someone assumes that is part of the numeric keypad, but unlikely (since the keypad uses different character sequences than the function keys).

That's assuming you used a terminal description that knows about the function keys. The vt100 terminal description doesn't do that, since vt100's had no function keys (other than PF1 through PF4 which are or aren't depending who you talk to). But if you had TERM=vt100, then some of the numeric keypad could be recognized on the basis of the terminal description (see for instance the lengthy comment above the vt100+fnkeys description).

It's not in TERM=xterm, however.

What you're overlooking is that vim (helpfully perhaps) amends the terminal description using its built-in termcaps. It recognizes PF1, etc. using table entries like this:

{K_XF1,             IF_EB("\033O*P", ESC_STR "O*P")},
{K_XF2,             IF_EB("\033O*Q", ESC_STR "O*Q")},
{K_XF3,             IF_EB("\033O*R", ESC_STR "O*R")},
{K_XF4,             IF_EB("\033O*S", ESC_STR "O*S")},

But there are no entries for the numbered keys; there's no "\033O*p" for the 0 key.

If vim has (in the terminal description) the k0, and you haven't mapped it to anything, vim will treat it as a literal 0. The same happens with k1, etc., in effect treating the function-keys and numeric keypad as the same thing.

For what it's worth, GNU screen does the same thing, but also for the numbered keys. If I run vim inside screen, vim will see only the 0's. A literal 0 in vim doesn't do much in command-mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文