16

Often when I'm in Insert mode, I'll hit Esc to get into Normal mode, and then immediately hit O to begin a new line above the cursor and go into Insert mode there.

But when I do that, there is a 1-second delay after I hit the O before there is any visible response. Furthermore if I begin typing the new text during that 1-second delay, if the new text begins with any of a certain set of characters (e.g. j,k,m,n,o), I end up in the middle of some other operation I didn't intend, often making a mess, at which point I have to stop and fumble around with undos and redos until I am reasonably sure I have undone the damage.

To avoid that unpleasantness, I've gotten in the habit of pausing for one second after every time I type O. But this slows me down and prevents me from being the vim speed demon I would otherwise be.

What causes this? Is there a fix or workaround?

15

This happens only in the terminal, but not in GVIM, right? The reason is that Vim cannot distinguish between the individual types keys and an ANSI Escape sequence starting with the same keys (i.e. ^[O..., <Esc> followed by O in your case).

You can read about all the underlying complexities at :help 'timeout' (and following options). There you also find a suggested configuration that alleviates the problem:

:set timeout timeoutlen=1000 ttimeoutlen=100
  • 3
    You can also use set noesckeys; this has the side effect of disabling the arrow keys (and perhaps some other keys?) in Insert mode though, so it may not be for everyone. – Martin Tournoij May 13 '15 at 15:25
  • 2
    @Carpetsmoker Regarding "set noesckeys"... that works, but only if in Insert mode. I know I said I was in Insert mode to begin with; however I also often do <Esc>O starting from Normal mode (mainly when I'm not 100% sure whether I'm starting in Insert or Normal mode) so I'd like something that works in that case too. – Don Hatch May 13 '15 at 20:53
  • 1
    @DonHatch You can use :nnoremap ^[O O, where ^[ is entered by pressing <C-v><Esc> (may also show up as <1b>). – Martin Tournoij May 13 '15 at 22:30
5

As a workaround, instead of ESCO, use Control+OO. The Control+O puts you in normal mode for one command, then returns you to insert mode when it is done.

1

How about:

Control+C O

There are some subtleties when using Control+C you should be aware of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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