Key Bindings¶
Warning
Development of Sublime Text has moved on to version 3.
As a result,
this branch for Sublime Text 2
will not be updated any more.
Please select the latest branch
in the panel on the bottom left
and consider updating Sublime Text.
Key bindings map key presses to commands.
File Format¶
Key bindings are stored in .sublime-keymap files and defined in JSON. All
key map filenames need to follow this pattern: Default (<platform>).sublime-keymap.
Otherwise, Sublime Text will ignore them.
Platform-Specific Key Maps¶
Each platform gets its own key map:
Default (Windows).sublime-keymapDefault (OSX).sublime-keymapDefault (Linux).sublime-keymap
Separate key maps exist to abide by different vendor-specific HCI guidelines.
Structure of a Key Binding¶
Key maps are arrays of key bindings. Below you’ll find valid elements in key bindings.
keys- An array of case-sensitive keys to be pressed. Modifiers can be specified
with the
+sign. Chords are built by adding elements to the array, e.g.["ctrl+k","ctrl+j"]. Ambiguous chords are resolved with a timeout. command- Name of the command to be executed.
args- Dictionary of arguments to be passed to
command. Keys must be the names of parameters tocommand. context- Array of contexts to selectively enable the key binding. All contexts must be true for the key binding to trigger. See Structure of a Context below.
Here’s an example illustrating most of the features outlined above:
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
]
}
Structure of a Context¶
key- Name of a context operand to query.
operator- Type of test to perform against
key. operand- Value against which the result of
keyis tested. match_all- Requires the test to succeed for all selections. Defaults to
false.
Context Operands¶
auto_complete_visible- Returns
trueif the autocomplete list is visible. has_next_field- Returns
trueif a next snippet field is available. has_prev_field- Returns
trueif a previous snippet field is available. num_selections- Returns the number of selections.
overlay_visible- Returns
trueif any overlay is visible. panel_visible- Returns
trueif any panel is visible. following_text- Restricts the test just to the text following the caret.
preceding_text- Restricts the test just to the text preceding the caret.
selection_empty- Returns
trueif the selection is an empty region. setting.x- Returns the value of the
xsetting.xcan be any string. text- Restricts the test just to the selected text.
selector- Returns the current scope.
panel_has_focus- Returns
trueif the current focus is on a panel. panel- Returns
trueif the panel given as operand is visible.
Context Operators¶
equal,not_equal- Test for equality.
regex_match,not_regex_match- Match against a regular expression.
regex_contains,not_regex_contains- Match against a regular expression (containment).
Command Mode¶
Sublime Text provides a command_mode setting to prevent key presses from
being sent to the buffer. This is useful when emulating Vim’s modal behavior.
Bindable Keys¶
Keys may be specified literally or by name. Here’s the list of valid names:
updownrightleftinserthomeendpageuppagedownbackspacedeletetabenterpauseescapespacekeypad0keypad1keypad2keypad3keypad4keypad5keypad6keypad7keypad8keypad9keypad_periodkeypad_dividekeypad_multiplykeypad_minuskeypad_pluskeypad_enterclearf1f2f3f4f5f6f7f8f9f10f11f12f13f14f15f16f17f18f19f20sysreqbreakcontext_menubrowser_backbrowser_forwardbrowser_refreshbrowser_stopbrowser_searchbrowser_favoritesbrowser_home
Modifiers¶
shiftctrlaltsuper(Windows key, Command key...)
Warning about Bindable Keys¶
If you’re developing a package, keep this in mind:
Ctrl+Alt+<alphanum>should not be used for any Windows key bindings.Option+<alphanum>should not be used for any OS X key bindings.
In both cases, the user’s ability to insert non-ASCII characters would be compromised.
If you are the end-user, you are free to remap those key combinations.
Keeping Key Maps Organized¶
Sublime Text ships with default key maps under Packages/Default. Other
packages may include their own key map files. The recommended storage location
for your personal key map is Packages/User.
See Merging and Order of Precedence for information about how Sublime Text sorts files for merging.
International Keyboards¶
Due to the way Sublime Text maps key names to physical keys, there might be a mismatch between the two.
Troubleshooting¶
To enable command logging, see sublime.log_commands(flag). This may help in debugging key maps.