问题
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