问题描述
我在使用ctrl键的vim中使用键映射遇到一些奇怪的行为.我想这有一个简单的原因和解决方案,但是我看不出来.
I am encountering some strange behavior with a keymap in vim that uses the ctrl key. I would guess that this has a simple cause and solution, but I just can't see it.
在编辑重组文本期间,我发现自己输入的内容是
During the editing of restructuredtext, I find myself typing things like
:math:`x`
经常
(此:math:角色将使刻度线内的所有内容被排版为数学形式,例如乳胶输出).
often (this :math: role will cause whatever is inside the ticks to be typeset as math in e.g. the latex output).
我想映射一个像这样的键在文本中输入:math:``并将光标定位在刻度线内.
I want to map a key like to enter :math:`` into the text and position the cursor inside the ticks.
我已经做到了
map m i:math:``ha
,这似乎很好.
但是,我希望能够在插入模式下使用此映射.为此,我认为最好使用 + .我完成了
However, I would like to be able to use this map in insert mode. For that, I thought that using + would be best. I've done
imap <c-m> :math:``ha
尽管我输入 + 时正确输入了:math:``并将光标定位在刻度内,但麻烦的是每次之后都在此之后我在插入模式下按,它运行的命令与输入 + 相同.换句话说,现在以插入模式进入似乎已映射到
Although that correctly inputs :math:`` and positions the cursor inside the ticks when I do +, the trouble is that after this point, every time I press in insert mode, it runs the same command as if I typed +. In other words, enter in insert mode now seems to be mapped to
:math:``ha
也是.
似乎与使用键有关.如果我绑定例如键,如下所示
It seems like it is definitely something to do with using the key. If I bind e.g. the key as follows
imap <F5> :math:``ha
一切都很好.
我可以使用密钥,省去了更多麻烦,但我想知道发生了什么事,以备将来参考.
I can use the e.g. key and save myself any further bother, but I would like to know what is going on for future reference.
在我丢失的密钥映射中使用密钥是否有一些基本知识?
Is there something basic about the use of the key in a key map that I am missing?
谢谢
推荐答案
您必须为映射使用其他控件组合,例如<C-g>
.
You have to use a different control combination for your mapping, e.g. <C-g>
.
由于内部处理键盘输入的方式,不幸的是,今天通常没有这些副作用,即使在GVIM中也无法实现.某些键组合(例如 +非字母)无法映射,并且 +字母与 + + non-alphabetic cannot be mapped, and + letter vs. + + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) This also applies to <Tab>
/ <C-I>
, <CR>
/ <C-M>
/ <Esc>
/ <C-[>
etc. (Only exception is <BS>
/ <C-H>
.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.
有些人(最重要的是Paul LeoNerd Evans)想解决这个问题(即使对于支持此功能的终端机中的控制台Vim),并提出了各种建议cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a
Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8
但是,到目前为止,还没有补丁或自愿者出现,尽管许多人表示希望在将来的Vim 8主要发行版中使用它.
But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.
这篇关于在vim中,enter被映射到ctrl键自定义键映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!