Contexts

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.



Available Contexts

selectorAll selections must match the given selector
allSelectionsEmptyAll selections must be empty
allSelectionsNonEmptyAll selections must be non-empty
allFollowingCharacterThe character to the right of each selection must be equal to the one given
noFollowingCharacterNo character to the right of any selection must be equal to the one given
allPrecedingCharacterThe character to the left of each selection must be equal to the one given
noPrecedingCharacterNo character to the left of any selection must be equal to the one given
optionThe given option must have a value of 'true'
notOptionThe given option must not have a value of 'true'
canPopSelectionIf the selection history can be poped
canUnpopSelectionIf the selection history can be unpoped
hasNextFieldIf a snippet is currently being inserted, and the last field is not active
hasPrevFieldIf a snippet is currently being inserted, and the first field is not active
newlineInSelectionAt least one selection includes a newline
hasMultipleSelectionsThere is more than one selection
noPrecedingTextFor each selection, the text between the beginning of the line and the selection must not match the given regex
allPrecedingTextFor each selection, the text between the beginning of the line and the selection must match the given regex
noContainedTextFor each selection, the text within the selection must not match the given regex
allContainedTextFor each selection, the text within the selection must match the given regex
noFollowingTextFor each selection, the text between the selection and the end of the line must not match the given regex
allFollowingTextFor each selection, the text between the selection and the end of the line must match the given regex
isPanelVisibleIf a panel is open
isOverlayVisibleIf an overlay is open (i.e., the quick panel)
isFullScreenIf the current window is in full screen mode