T
T
Treniki2017-02-15 10:52:56
Macros
Treniki, 2017-02-15 10:52:56

How to write a macro in Sublime Text 3?

Good day. I want to write a macro that, using hot keys, will add certain characters to the selected text. For example, the text "67px", I select it, press the hot key combination, and it will be converted to "(67px / 2)". Those. this text is separated by brackets, and inside - the value is divided by 2. How to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iBird Rose, 2017-02-15
@Treniki

create a snippet

<snippet>
    <content><![CDATA[(${0:$TM_SELECTED_TEXT}/2)]]></content>
    <tabTrigger>dd</tabTrigger>
    <scope>source.js</scope> //тут указываешь виды файлов где будет работать сниппет. можно через запятую
    <description>dd</description>
</snippet>

save the snippet in the sublime folder. approximately here "C:\Users\*username*\AppData\Roaming\Sublime Text 3\Packages\User\dd.sublime-snippet" then
go to Preferences -> Key Bindings and hammer in the key.
{
    "keys": ["ctrl+shift+1"], 
    "command": "insert_snippet",
    "args": {"name": "Packages/User/dd.sublime-snippet"}
  }

actually everything. when you select any text and press ctrl+shift+1, the sublime will wrap it in ( *text here* /2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question