Sublime Text 2 Vintage: Leave insert mode on focus lost

sublime-text-2

I'm using Vintage mode (Vi bindings) on Sublime Text 2.

When switching back to ST2, I regularly get bitten by still being in insert mode, resulting in me entering "jjjjjjjjjjjjkkkkkkkkk".

Is there a way to automatically leave insert mode and go back to command mode when the ST2 window loses focus?

Best Answer

I've never used Sublime Text 2, but it looks like it might have promise... not changing from my Vim though {Grin}

The following SHOULD work for you to turn off Insert Mode when you lose focus, name it "stop_insert_on_focus_lost.py" and place it somewhere in your plugins folder.

Hopefully it'll work, had to scan the API and some of their example plugins to get the format and commands. (never seen ST2 before though... do I get points for grokking their API, Python & Vintage mode in a few minutes?)

import sublime, sublime_plugin
import os.path

class StopInsertOnFocusLost(sublime_plugin.EventListener):
    def on_deactivated(self, view):
        view.run_command('exit_insert_mode')
Related Question