I've been digging into Sublime's snippets, plugins and macros, but I can't seem to find what I'm looking for.
I'm trying to turn this:
.content { color: @blue; }
Into this:
.content { color: darken(@blue, 5%); }
Ideally, I'd be able to select the @blue
part, hit a command, and wrap the whole thing properly.
Any ideas? Is this even possible?
To wrap your selected content with a html tag, just selected your text, then press Alt-Shift-W.
You can create the default snippet using Tools → Developer → Snippet option. To create a first snippet in Sublime Text editor, click the Tools menu and select the Snippets option from the drop down window, as shown in the screenshot here. Now, choose Snippet:html from the options displayed.
To create a new snippet, select Tools | New Snippet…. Sublime Text will present you with an skeleton for a new snippet. Snippets can be stored under any package's folder, but to keep it simple while you're learning, you can save them to your Packages/User folder.
Go to Developer Option: Go to the developer option and click on New Snippet. A file will be open with some pre-written code.
As can be seen here:
Tools -> New Snippet... -> save as darken.sublime-snippet
in Data\Packages\User\
<snippet> <content><![CDATA[darken($SELECTION, 5%);]]></content> <!-- Optional: Tab trigger to activate the snippet --> <tabTrigger>darken</tabTrigger> <!-- Optional: Scope the tab trigger will be active in --> <scope>source.css</scope> <!-- Optional: Description to show in the menu --> <description>Darken Snippet</description> </snippet>
And keybind:
{ "keys": ["ctrl+shift+o"], "command": "insert_snippet", "args": { "name": "Packages/User/darken.sublime-snippet" } },
EDIT: It would be even better if you add $1
right after the $SELECTION
, then the cursor will jump to the selected word or right in the place where it has to be written if it's not selected.
Change the above snippet's second line to this:
<content><![CDATA[darken($SELECTION$1, 5%);]]></content>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With