问题
Problem
I am in insert mode
, and then I might type a number, and then quickly ESC, because I stopped typing so it will change to visual mode
.
What happens then, is that the cursor
jumps, and not only that, the number on the line that I was (and I just typed) is decremented.
This thing is a nightmare!
What is causing this?
Is this some kind of default behavior? If so, how can I disable it? Could this be a plugin causing it? Because I didn't always had this "feature". I was trying for some months to figure out what is causing this, and I've posted this generic question.
Especially when programming, number auto-decrement can cause lot of headaches, so I've disabled the default mapping for it, by mapping <C-a> <Nop>
in my .vimrc
; more info here.
回答1:
Your issue seems linked to the 'timeout'
option, and its friends 'timeoutlen'
, 'ttimeout'
, 'ttimeoutlen'
.
Try this command:
:set timeout timeoutlen=3000 ttimeoutlen=100
It's taken from :h 'ttm
:
The timeout only happens when the 'timeout' and 'ttimeout' options tell so. A useful setting would be :set timeout timeoutlen=3000 ttimeoutlen=100 (time out on mapping after three seconds, time out on key codes after a tenth of a second).
Personally, I use these settings:
set timeout
set ttimeout
set timeoutlen=3000
set ttimeoutlen=50
The first 2 commands enable a timeout on mappings and keycodes respectively.
The 3rd command set timeoutlen=3000
tells Vim to wait 3s
to let me finish typing the left-hand-side of a mapping.
The 4th command set ttimeoutlen=50
tells Vim to only wait 50ms
for a sequence of keycodes to finish. For example, on my machine, F1
produces the sequence of keycodes Escape O P
(confirmed by typing C-v F1
in insert mode, which displays ^[OP
; ^[
stands for Escape
).
It's possible that your original issue comes from the fact that the value of your 'ttimeoutlen'
option is too high, and therefore the timeout for a sequence of keycodes doesn't occur soon enough, allowing Vim to sometimes interpret a sequence of keystrokes you type as produced by some other key you didn't press. By reducing its value, you may prevent this.
If your issue persists even though you set the previous options in your vimrc
, it's possible that a plugin changes them afterwards.
In this case, when your issue occurs again, type these commands:
:verb set timeout?
:verb set ttimeout?
:verb set timeoutlen?
:verb set ttimeoutlen?
Each of them will tell you the current value of your options, but more importantly it will tell you the name of the last file which changed the value.
来源:https://stackoverflow.com/questions/44890662/disable-timeout-on-esc-key