90

I've noticed that, occasionally, when I use O (capital 'o') to create a new line and go into insert mode, there is a short delay before anything happens.

Is this common? Is there any way to change it?

Both :map O and :imap O show "No mapping found", so I don't think it's a strange mapping.

4
  • Agree about the superuser.com: perhaps this is due to syntax highlighting recalculating the formatting ?
    – monojohnny
    Jan 28, 2010 at 22:39
  • 5
    Please do not use tags like "belongs-on-superuser" Tags are not intended as a means for you to express your opinion - see meta.stackexchange.com/questions/36819/…. If you think it belongs on SU, vote to move it there.
    – anon
    Jan 28, 2010 at 22:45
  • I have been corrected. I'll not use those tags anymore. I still think this very good question is the kind of question that belongs on SU and hope to find it there.
    – jjclarkson
    Feb 1, 2010 at 21:11
  • Yea, sorry - you're right. This should be on SU. Is there a quick and easy button I can use to migrate it (and the answers?) Feb 1, 2010 at 21:22

3 Answers 3

100

It's because the 'esckeys' option is enabled (a consequence of nocompatible as I just discovered). When you press ^[O, there's a small delay as it figures out if you're using an arrow/function key or if you just meant those two keys in sequence.

One solution is to disable that option and give up on the arrow keys in insert mode.
Another is to set 'timeoutlen' to something less than 1000, maybe 100 (but be careful over slow connections).
Another is to use ^C instead of ^[ to leave insert mode.

6
  • Cool, thanks! Also, for anyone else who might be reading this: before turning it off, check the help page for 'esckeys' - it's what lets you use, eg, the arrow keys in insert mode. Setting 'timeoutlen' worked nicely for me. Jan 29, 2010 at 15:16
  • 3
    Also ttimeoutlen can set timeout for just keycodes. See vim's :help ttimeoutlen
    – k107
    Jul 11, 2012 at 23:44
  • 1
    I still have the delay even after :set noesckeys or :set timeout timeoutlen=1000 ttimeoutlen=100... Any ideas? (Cygwin, VIM compiled from source) Mar 5, 2013 at 6:28
  • 2
    Worked fine for me with :set timeout timeoutlen=3000 ttimeoutlen=100 (as advised in vim help). Just purely setting timeoutlen to a small value was a bad idea - some mappings stopped working.
    – jkff
    Apr 12, 2013 at 21:49
  • I don't get it. When 'esckeys' is enabled, why can't I type the sequence <esc>[A in insert mode to move the cursor up?
    – Qian
    Jul 31, 2016 at 17:47
4

It happens if you press "O" right after the Escape key, right? I always assumed it was because the terminal driver was waiting a bit to see if you were going to complete an escape sequence.

0

I suspect it's when you have to write the swapfile to disk. Make sure that you are running vim on a computer with fast disk access; if you have to use a shared filesystem you can try moving the swap file using

:set directory=/path/to/local/dir
4
  • I second this - at work our home directories are NFS-mounted, and I see this kind of delay a lot.
    – Cascabel
    Jan 28, 2010 at 22:46
  • ...of course, if it's only for O, not o, it's certainly the escape key sequence thing, as jleedev says!
    – Cascabel
    Jan 28, 2010 at 23:00
  • 1
    Well, even though this answer directly doesnt address OP, I feel its still relevant. Cannot agree with the person who down-voted. Jan 29, 2010 at 14:16
  • Wasn't the answer to OP's problem, but a good theory and instructive explanation. Thanks!
    – supervacuo
    Jul 15, 2012 at 21:17

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.