Sublime Forum

Usage of $TM_SELECTED_TEXT

#1

hello,

how can I make use of $SELECTION? A similar question has been asked here.

When I select a text in the editor, then go to Tools / Snippets… and select my snippet the selected text is not inserted.

My snippet:

<snippet>
    <content><![CDATA[
---------------
$TM_SELECTION
---------------
]]></content>
    <tabTrigger>fancySnippet</tabTrigger>
</snippet>

the output:

---------------

---------------

I don’t understand why it is not working. According to the other thread, it works in the console with

>>> view.run_command('insert_snippet', {'name':'Packages/User/fancy_snippet.sublime-snippet'})

but even that is not working.

Can anyone explain how $SELECTION should be used?

thank you

0 Likes

#2

I believe that this is not working for you because the variable that represents the selection is $TM_SELECTED_TEXT (or $SELECTION) and not $TM_SELECTION. Something like the following should work for you:

<snippet>
    <content><![CDATA[
--------------------
${TM_SELECTED_TEXT}
--------------------
]]></content>
    <tabTrigger>fancySnippet</tabTrigger>
</snippet>
2 Likes