Home Download Buy Blog Forum Support

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

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

Postby handycam on Tue Nov 20, 2012 12:44 am

Assuming I have a snippet called "My Snippet.sublime-snippet", what's the syntax in the keymap file to call this snippet?
Mac OS 10.8.5
ST 3 (3053)
handycam
 
Posts: 269
Joined: Tue Jan 03, 2012 2:42 pm

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

Postby C0D312 on Tue Nov 20, 2012 1:04 am

There should be examples of these in the default keymap. Check there.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

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

Postby agibsonsw on Tue Nov 20, 2012 1:07 am

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


I prefer to remove the space (personally).
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

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

Postby handycam on Tue Nov 20, 2012 1:41 am

thanks!
Mac OS 10.8.5
ST 3 (3053)
handycam
 
Posts: 269
Joined: Tue Jan 03, 2012 2:42 pm

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

Postby handycam on Tue Nov 20, 2012 1:45 am

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

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


Snippet:
Code: Select all
<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>
Mac OS 10.8.5
ST 3 (3053)
handycam
 
Posts: 269
Joined: Tue Jan 03, 2012 2:42 pm

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

Postby agibsonsw on Tue Nov 20, 2012 1:50 am

ctrl+shift+b

As mentioned by COD312, you should examine the default key-bindings to guide you.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

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

Postby handycam on Tue Nov 20, 2012 2:23 am

agibsonsw wrote:ctrl+shift+b

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


Damn. What a jerk I am. Thanks.
Mac OS 10.8.5
ST 3 (3053)
handycam
 
Posts: 269
Joined: Tue Jan 03, 2012 2:42 pm


Return to General Discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 18 guests