[英]Why does Vim delay on this remapped key? And how do I fix it?
I have the following lines in my vimrc: 我的vimrc中有以下几行:
noremap gb vnoremap gb
The goal of these is pretty clear: move one word to the left whenever I press g. 这些的目标非常明确:每当我按下g时,向左移动一个单词。
My issue is that there is a delay of about 1/2 second before vim executes the move. 我的问题是在vim执行移动之前有大约1/2秒的延迟。 It is as if vim is waiting for me to enter an addition command.
好像vim正在等我输入一个加法命令。
I know vim does this kind of thing when it is expecting more information. 我知道vim在期待更多信息时会做这种事情。 However, this is the only case where I have a remap that involves g, so it's unlikely to be the case.
但是,这是我唯一一个涉及g的重映射的情况,因此不太可能出现这种情况。
Other people seem to be having similar problems: Eliminating lag when remapping 'd' key in VIM 其他人似乎也有类似的问题: 在VIM中重新映射'd'键时消除了延迟
But no one has yet offered a solution. 但还没有人提供解决方案。
Any thoughts? 有什么想法吗?
If I do this and start vim using vim -u NONE -N
I can't replicate the behaviour. 如果我这样做并使用
vim -u NONE -N
启动vim,我无法复制该行为。 Looking further, this seems to be caused by the netrw plugin, which maps the gx
key as well as the matchit plugin, that maps g%
. 进一步看,这似乎是由netrw插件引起的,它映射了
gx
键以及映射g%
的matchit插件。 (You might to check using :verbose :map g
to see, if there are other ambigious g mappings that could cause this and where they were defined (by the use of :verbose
)). (您可以使用
:verbose :map g
来查看,如果存在其他可能导致此问题以及它们被定义的地方(通过使用:verbose
),则可以:verbose
。
So to prevent this, you should unmap those mappings and then the g
works without delay. 因此,为了防止这种情况,您应该取消映射这些映射,然后
g
工作无延迟。 But as progo already said, you lose all those nice builtin g<x>
commands, so I would not recommend to map g
away 但正如progo已经说过的那样,你失去了所有那些漂亮的内置
g<x>
命令,因此我不建议将g
映射掉
Note also, recent vims have the <nowait>
modifier, so you can just do noremap <nowait> gb
and no delay will occur. 另请注意,最近的vims具有
<nowait>
修饰符,因此您可以执行noremap <nowait> gb
并且不会发生延迟。
But vim is expecting more information. 但VIM 期待更多的信息。 There is a bunch of normal mode key bindings that start with
g
such as ( gg
, gd
, gf
, gq
, ...) and of course vim has to wait until it knows what you started to type in. 有一堆普通模式键绑定以
g
开头,例如( gg
, gd
, gf
, gq
,...),当然vim必须等到它知道你开始输入的内容。
This is a situation you can't really fix without breaking lots of other mappings. 这是一种在不破坏大量其他映射的情况下无法真正解决的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.