Is it possible to make Vim automatically exit whatever mode it's in and return to normal mode when the terminal window loses focus?
Add this to your vimrc:
autocmd FocusLost * call feedkeys("\<esc>")
This essentially means "If we lose focus (
autocmd FocusLost) on any filetype (
*), then type an escape key as if I pressed it (
As Statox pointed out in the comments, this will only work for GVim, and certain terminals.