Within key bindings, contexts can be used to limit the scope of a key binding, to allow the same key binding to do different things in different circumstances. You can see an example of this with the tab key: If the selection contains newlines, it runs the indent command, otherwise it just inserts a tab.
An example:
<binding key="tab" command="insertAndDecodeCharacters \t"/>
<binding key="tab" command="indent">
<context name="newlineInSelection" value="true"/>
</binding>
Here there are two key bindings for tab, the latter will only be used when the newlineInSelection context is true.
More examples can be seen in Packages/Default/Default.sublime-keymap.
| selector | All selections must match the given selector |
| allSelectionsEmpty | All selections must be empty |
| allSelectionsNonEmpty | All selections must be non-empty |
| allFollowingCharacter | The character to the right of each selection must be equal to the one given |
| noFollowingCharacter | No character to the right of any selection must be equal to the one given |
| allPrecedingCharacter | The character to the left of each selection must be equal to the one given |
| noPrecedingCharacter | No character to the left of any selection must be equal to the one given |
| option | The given option must have a value of 'true' |
| notOption | The given option must not have a value of 'true' |
| canPopSelection | If the selection history can be poped |
| canUnpopSelection | If the selection history can be unpoped |
| hasNextField | If a snippet is currently being inserted, and the last field is not active |
| hasPrevField | If a snippet is currently being inserted, and the first field is not active |
| newlineInSelection | At least one selection includes a newline |
| hasMultipleSelections | There is more than one selection |
| noPrecedingText | For each selection, the text between the beginning of the line and the selection must not match the given regex |
| allPrecedingText | For each selection, the text between the beginning of the line and the selection must match the given regex |
| noContainedText | For each selection, the text within the selection must not match the given regex |
| allContainedText | For each selection, the text within the selection must match the given regex |
| noFollowingText | For each selection, the text between the selection and the end of the line must not match the given regex |
| allFollowingText | For each selection, the text between the selection and the end of the line must match the given regex |
| isPanelVisible | If a panel is open |
| isOverlayVisible | If an overlay is open (i.e., the quick panel) |
| isFullScreen | If the current window is in full screen mode |