Sublime Text: how to make shortcut for inserting text?

skyisred picture skyisred · Mar 23, 2013 · Viewed 29.9k times · Source

I need make a shortcut that will be adding certain text at the cursor, eg {sometext}, how can this be done?

Answer

Greg Sadetsky picture Greg Sadetsky · Mar 23, 2013

Select the Key Bindings - User item under Sublime's Preferences, then add the following example line:

{"keys": ["ctrl+shift+c"], "command": "insert_snippet", "args": {"contents": "hello!"}}

This will add a CTRL+SHIFT+C shortcut to insert the hello! snippet.

By the way, don't forget to add a comma to the previous key binding hash so that all but the last line end with a comma. i.e.:

[
    {"keys": ["..."], "command": "..." },
    {"keys": ["..."], "command": "..." },
    {"keys": ["..."], "command": "..." },
    {"keys": ["ctrl+shift+c"], "command": "insert_snippet", "args": {"contents": "hi!"}}
]