Sublime Forum

$SELECTION snippet

#1

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

0 Likes

#2

It looks like he has a snippet that prints out[code] <!-- CSS – >
$1

[/code]

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

0 Likes

#3

[quote=“C0D312”]It looks like he has a snippet that prints out[code] <!-- CSS – >
$1

[/code]

Then he just cuts his text, types snippet, presses tab, and presses paste.[/quote]

:astonished: Didn’t think about this way, but if the truth is like this, I’m sad. :frowning:

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.

0 Likes

$SELECTION snippet combined with key binding, on Mac
#4

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]

[/code]

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

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

#5

[quote=“abathologist”]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]

[/code]

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

{ "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]{ “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 }
]

}[/code]

The equal means it works only in source.python the not_equal means exclude comment.blah scopes.

1 Like