on_query_context(view, key, operator, operand, match_all)
On_query_context is awesome. Unfortunately, I can't show you an example from my code (my plugin's not released yet) but you can check out usage in the Vintage package.
Essentially, when you set up a keybinding, you can create your own custom 'contexts.' If your context matches, the binding is captured, else it is ignored.