This is a job for snippets and the insert_snippet
command in particular. The key binding that you’re talking about is this one (ctrl+shif+w closes the current window, unless you happen to have remapped it):
{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/XML/Snippets/long-tag.sublime-snippet" } },
The short version of the answer to your question is that you can use the same command and use the contents
argument rather than the name
argument to inline the snippet content that you want. Thus your key would look something like this:
{
"keys": ["ctrl+shift+c"],
"command": "insert_snippet",
"args": {
"contents": "<span class=\"code\">${0:$SELECTION}</span>"
},
},
If you want the key to only work inside of HTML files, add this to the binding after the args
(make sure that there is a comma after the args as above):
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.html" },
]
For a longer version of the answer that explains how all of this works and what it’s doing, see this SO question as well as the unofficial documentation on snippets.