Home Download Buy Blog Forum Support

$SELECTION snippet

$SELECTION snippet

Postby prmaple on Sat Mar 17, 2012 11:29 am

Hi all,

I know that I can build snippet to wrap things with the use of $SELECTION,

just being curious that if there is anyway I can use a snippet to wrap something

WITHOUT invoking the snippet from the command palette?

Being more specific, I saw the use in this video: http://www.youtube.com/watch?v=MYZ7eSR-7_8
at 1:50


Thanks

Po
Find me
HTML5 Games: SNAKE! Tetris!
prmaple
 
Posts: 82
Joined: Sun Dec 25, 2011 11:06 am
Location: Melbourne

Re: $SELECTION snippet

Postby C0D312 on Sat Mar 17, 2012 12:50 pm

It looks like he has a snippet that prints out
Code: Select all
<!-- CSS -- >
$1
<!-- end CSS -->

Then he just cuts his text, types snippet, presses tab, and presses paste.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: $SELECTION snippet

Postby prmaple on Sat Mar 17, 2012 1:50 pm

C0D312 wrote:It looks like he has a snippet that prints out
Code: Select all
<!-- CSS -- >
$1
<!-- end CSS -->

Then he just cuts his text, types snippet, presses tab, and presses paste.



:o Didn't think about this way, but if the truth is like this, I'm sad. :(

Thank you for your reply anyway.

I've seen tons of your posts. It seems that you're a very old sublime user.

Hello and Shake hand. haha.
Find me
HTML5 Games: SNAKE! Tetris!
prmaple
 
Posts: 82
Joined: Sun Dec 25, 2011 11:06 am
Location: Melbourne

Re: $SELECTION snippet

Postby abathologist on Thu Mar 22, 2012 12:03 am

If I understand you correctly, you can just assign a keybinding to trigger the snippet. For example, I use the following snippet to wrap text with asterisks for Markdown:

Code: Select all
<snippet>
  <content><![CDATA[
*${SELECTION}*
]]></content>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <!-- <scope>source.python</scope> -->
</snippet>


Then I set the following keybinding in my user keymap prefs:

Code: Select all
{ "keys": ["super+shift+i"], "command": "insert_snippet", "args": {"name": "Packages/User/md-ital.sublime-snippet" }}
abathologist
 
Posts: 18
Joined: Thu Mar 15, 2012 1:29 am

Re: $SELECTION snippet

Postby atomi on Thu Mar 22, 2012 12:43 am

abathologist wrote:If I understand you correctly, you can just assign a keybinding to trigger the snippet. For example, I use the following snippet to wrap text with asterisks for Markdown:

Code: Select all
<snippet>
  <content><![CDATA[
*${SELECTION}*
]]></content>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <!-- <scope>source.python</scope> -->
</snippet>


Then I set the following keybinding in my user keymap prefs:

Code: Select all
{ "keys": ["super+shift+i"], "command": "insert_snippet", "args": {"name": "Packages/User/md-ital.sublime-snippet" }}



Not only that you can also add snippets inline and add context.

Code: Select all
{ "keys": ["super+shift+i"], "command": "insert_snippet", "args": {"contents": "*${SELECTION}*" },
    "context":
    [
        {"key": "selector", "operator": "equal", "operand": "source.python", "match_all": true },
        {"key": "selector", "operator": "not_equal", "operand": "comment", "match_all": false }
    ]
}


The equal means it works only in source.python the not_equal means exclude comment.blah scopes.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 17 guests