llinfeng
llinfeng

Reputation: 1395

How to exit insert mode using autocommand upon losing focus?

Currently, I am using the following command as suggested by Auto save files when focus is lost.

autocmd FocusLost * wall!

However, I cannot apply <ESC> trailing the wall!. Vim will complain about it and I partially enter normal mode. (The message-box actually takes the focus of cursor.)

Any suggestion on how to realize the action of: "auto-save + return to normal mode", upon "losing focus"?

Thank you!

All the best,

-Linfeng

Upvotes: 2

Views: 522

Answers (1)

orlp
orlp

Reputation: 117671

Try using stopinsert:

autocmd FocusLost * stopinsert | wall!

Upvotes: 3

Related Questions