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.
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.
- I think this may already have been done with some plugin somewhere... every time I think of something I assume I'm not the first to have come up with it or to have the need for it. – icedwater Commented Feb 17 at 3:33
- 1 This one? – Robby Cornelissen Commented Feb 17 at 3:37
2 Answers
Reset to default 6augroup 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.
You could use stopinsert.nvim Neovim plugin => https://github/csessh/stopinsert.nvim
More complete than using an autocommand:
- dedicated option for idle time before leaving Insert mode
- disable plugin for specific filetypes