在vim中映射数字键盘按键
我无法让此映射在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将此行添加到您的
~/.Xdefaults
:并重新启动 xterm。
“应用程序键盘模式”可能是您遇到麻烦的原因。
但我认为你不应该做你正在做的事情。在
--NORMAL--
模式下,数字输入用于指示“计数”,如4dd
中那样。将数字映射到其他命令很快就会给你带来麻烦。您应该在问题中添加
xterm
标签。Try to add this line to your
~/.Xdefaults
: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 in4dd
. Mapping numbers to other commands is going to get you into troubles fast.You should add a
xterm
tag to your question.问题中有一些含糊之处,这可能表明了实际的问题。 vim 接受
k0
的绑定,假设它是一个功能键。您会看到的大多数键盘都是从
1
开始的数字功能键,并且一些终端描述将功能键 1 等同于k0
,很少有人将其k0
等同于功能键 10。也有可能有人认为它是数字键盘的一部分,但可能性不大(因为键盘使用的字符序列与键盘使用的字符序列不同)。功能键)。假设您使用了了解功能键的终端描述。 vt100 终端描述不会这样做,因为 vt100 没有功能键(PF1 到 PF4 除外,这取决于您与谁交谈)。但是,如果您有
TERM=vt100
,那么可以根据终端描述识别数字键盘的一些(例如,参见vt100+fnkeys
说明)。然而,它不在
TERM=xterm
中。您忽略的是 vim (也许有帮助)使用其内置 termcap 修改终端描述。它使用如下表条目来识别 PF1 等:
但是没有编号键的条目;
0
键没有"\033O*p"
。如果 vim (在终端描述中)有
k0
,并且您没有将其映射到任何内容,vim 会将其视为文字0
。k1
等也会发生同样的情况,实际上将功能键和数字键盘视为同一事物。就其价值而言,GNU
screen
可以做同样的事情,而且还可以用于数字键。如果我在screen
内运行vim
,vim
将只看到 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 tok0
, a few equate itk0
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 thevt100+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:
But there are no entries for the numbered keys; there's no
"\033O*p"
for the0
key.If vim has (in the terminal description) the
k0
, and you haven't mapped it to anything, vim will treat it as a literal0
. The same happens withk1
, 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 runvim
insidescreen
,vim
will see only the 0's. A literal0
in vim doesn't do much in command-mode.