3

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 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

thanks for the detailed answer. When I started using vim I used other people's popular vimrcs, and since then I slowly removed most of that crap. I still have some leftovers in a legacy.vim file and the issue was coming from there!
Still got some of those issues. Numbers are fixed, but still have to reproduce the others.
@Paschalis Ah sorry about that. If you can reproduce your other issues, you could ask another question, and maybe someone will find a solution. If possible, try to reproduce it with a minimum of sourced files and a minimal vimrc (vim -Nu my_short_vimrc). There are many options in Vim, maybe one of them is not configured like it should. Have a look at the :opt command. It should open a window where most (all?) options are displayed, and sorted by category. It's an interactive window, so you can temporarily change their values from there.

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.