Sublime Forum

How to create a key binding to call a snippet by name?

#1

Assuming I have a snippet called “My Snippet.sublime-snippet”, what’s the syntax in the keymap file to call this snippet?

0 Likes

#2

There should be examples of these in the default keymap. Check there.

0 Likes

#3
{ "keys": "alt+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/User/My Snippet.sublime-snippet" } }

I prefer to remove the space (personally).

0 Likes

#4

thanks!

0 Likes

#5

OK, it doesn’t work for me, I’m sure it’s something stupid.

Key command:

{ "keys": "shift-ctrl-b"], "command": "insert_snippet", "args": { "name": "Packages/User/Strong.sublime-snippet" } }

Snippet:

<snippet> <content><![CDATA[ <strong>$SELECTION</strong> ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- <tabTrigger>hello</tabTrigger> --> <!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- <scope>source.python</scope> --> </snippet>

0 Likes

#6

ctrl+shift+b

As mentioned by COD312, you should examine the default key-bindings to guide you.

0 Likes

#7

[quote=“agibsonsw”]ctrl+shift+b

As mentioned by COD312, you should examine the default key-bindings to guide you.[/quote]

Damn. What a jerk I am. Thanks.

0 Likes