Sublime Text wrap selection with snippet

别来无恙 提交于 2019-12-04 07:41:08

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/12165364/sublime-text-wrap-selection-with-snippet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!