vimneovim

Return to normal mode when I stop typing


When I edit files in vim I mostly stay in the normal mode. To type text I go to the insert mode, but eventually I stop typing to "think". Usually, that's the moment when I need to hit <Esc>. How can I have vim automatically return to normal mode after I am idle in the insert mode for too long?

I know some remap <Esc> to ff, for convenience, but I would like to go back to normal mode automatically without having to hit any key at all.


Solution

  • augroup vimrc_example | au!
    autocmd CursorHoldI * stopinsert
    augroup end
    

    Make sure to see :h CursorHoldI and :h 'updatetime' to understand how it works.

    Note, however, that "usually" is too far away from "always", so such "auto-helpers" often bring more problems than they solve.