Prevent leaving terminal mode

  1. Neovim with mouse enabled
  2. 2 windows, one with some normal buffer, another with terminal
  3. You are in the terminal window, hacking away in terminal mode
  4. You click the other window with the mouse

What happens now is that neovim will switch to another window, but at the same time the previous terminal window will leave the terminal mode and return to the normal mode. Meaning that when I decide to return to the terminal window, I have to press an additional key to enter into terminal mode again.

Is it possible to prevent this? All I want is the terminal window to stay in the same mode when I leave it.

How about this?

autocmd WinEnter term://* startinsert

This is not exactly what I wanted, as it does not preserve the state of the terminal window. For example, if I was in a normal mode before leaving the terminal window, I will return to the terminal mode. But, considering that this is what I want in 90% of the time, this fix is definitely worth it!

A question - I tried using startinsert with TermEnter event, unsuccessfully. Any idea why?