How to hide Sublime inline errors (phantoms) with Escape

Unfortunately, at the moment Sublime Text (at the time of writing, build 3126) does not have a context that you can use in a keybinding to tell when inline build error phantoms are shown. This has been briefly discussed in the ST forums so it is possible that a future build will contain this functionality.

In the meantime, inspired by this post, we could potentially try to create a keybinding that won't conflict with the default Esc behavior. But it's worth bearing in mind that the default keybindings may change so we will need to watch for it when updating ST, to see whether this is still relevant/correctly covers all scenarios:

{ "keys": ["escape"], "command": "exec", "args": { "hide_phantoms_only": true },
    "context":
    [
        // inverse of all the "escape" key contexts found in the Default keybindings
        { "key": "num_selections", "operator": "equal", "operand": 1 },
        { "key": "has_next_field", "operator": "equal", "operand": false },
        { "key": "has_prev_field", "operator": "equal", "operand": false },
        { "key": "panel_visible", "operator": "equal", "operand": false },
        { "key": "overlay_visible", "operator": "equal", "operand": false },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]
}

Tags:

Sublimetext3