Last active
July 16, 2019 07:45
-
-
Save frontendbeast/504352ed3fb266965928 to your computer and use it in GitHub Desktop.
Simple example of a key-mapped Sublime Text snippet (⌘+b for bold)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
<strong>${TM_SELECTED_TEXT}</strong> | |
]]></content> | |
<scope>source.html</scope> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ "keys": ["super+b"], "command": "insert_snippet", "args": {"name": "Packages/User/bold.sublime-snippet"} }, | |
// Set context so shortcut works in HTML files only | |
{ "keys": ["super+b"], "command": "insert_snippet", "args": {"name": "Packages/User/bold.sublime-snippet"},"context":[{ "key": "selector", "operator": "equal", "operand": "text.html" }] } | |
] |
You can set the context for the keyboard shortcut, so it only works in certain scopes. See the example above for a simple implementation. The beauty of the scope context is that you can limit it from being HTML right down to a paragraph within a section element for example.
You'll want to use something like ScopeHunter to find the scope.
Check the key bindings docs for the operator and operand settings. With those regex options you can do anything!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add the snippet to your Packages/User folder and then go to 'Preferences' > 'Key Bindings – User' to add a keyboard shortcut.