Why does Vim delay on this remapped key? And how do I fix it?

戏子无情 提交于 2020-01-04 14:11:40

问题


I have the following lines in my vimrc:

noremap g b vnoremap g b

The goal of these is pretty clear: move one word to the left whenever I press g.

My issue is that there is a delay of about 1/2 second before vim executes the move. It is as if vim is waiting for me to enter an addition command.

I know vim does this kind of thing when it is expecting more information. However, this is the only case where I have a remap that involves g, so it's unlikely to be the case.

Other people seem to be having similar problems: Eliminating lag when remapping 'd' key in VIM

But no one has yet offered a solution.

Any thoughts?


回答1:


If I do this and start vim using vim -u NONE -N I can't replicate the behaviour. 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%. (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)).

So to prevent this, you should unmap those mappings and then the g works without delay. But as progo already said, you lose all those nice builtin g<x> commands, so I would not recommend to map g away

Note also, recent vims have the <nowait> modifier, so you can just do noremap <nowait> g b and no delay will occur.




回答2:


But vim is expecting more information. 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.

This is a situation you can't really fix without breaking lots of other mappings.



来源:https://stackoverflow.com/questions/26395562/why-does-vim-delay-on-this-remapped-key-and-how-do-i-fix-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!