Sublime Forum

How to insert a snippet from a plugin?

#1

I write a plugin where i would like to insert a snippet (Packages/XML/long-tag.sublime-snippet) via self.view.run_command("insert_snippet"...
Does anybody know if this is possible? I can’t figure it out. The snippet content looks like this:

<content><![CDATA[<${1:p}>${2:$SELECTION}</${1/([^ ]+).*/$1/}>]]></content>

Thanks

0 Likes

#2

Looks like the syntax is

self.view.run_command("insert_snippet", { "name": "Packages/User/MySnippet.sublime-snippet" })

to use a snippet file, or

self.view.run_command("insert_snippet", { "contents": "contents($0)" })

to insert a snippet string.

1 Like

Let curser focus on a certain string or region with commands
#3

Thanks, that’s actually what i tried. It didn’t work because of a prepending self.view.sel().clear(). Without clearing everything works fine now.

0 Likes

#4

Heh. You removed the cursor by doing that…

0 Likes