Sublime Forum

Insert snippet / long-tag issue

#1

Hey there,

I am having a weird issue with this default functionality in Sublime

{ "keys": "ctrl+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/XML/long-tag.sublime-snippet" } },

You can see a screencast here. Basically, I hit ctrl+shift+w to wrap text in a tag, or create a new tag then tab into it. However when I hit return inside of the generated tag and try to tab into the appropriate spot, I end up at the end of the next line. (watch the video, hard to describe)

Is there any way to fix this?

0 Likes

#2

That behavior is caused by a tab field somewhere. You can cancel the field by pressing escape.

0 Likes

#3

Here’s a possible alternative, which causes the snippet to end after the first tab marker, but before the selected text (if any).

  1. Create a new snippet (Tools -> New snippet…)

  2. Paste in this code, which is a slightly modified version of the relevant snippet in the XML package:

<snippet>
    <content><![CDATA[<${1:p}>$0$SELECTION</${1/([^ ]+).*/$1/}>]]></content>
    <tabTrigger>&lt;</tabTrigger>
    <scope>text.xml</scope>
    <description>Long Tag</description>
</snippet>
  1. Save this snippet in the “User” package folder as long-tag.sublime-snippet (you can call it anything, but I use the same file name as the snippet in the XML package, just to help me remember what I’m overriding).

  2. In the User Key Bindings, add:

{ "keys": "ctrl+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/User/long-tag.sublime-snippet" } }

After saving the new key binding, the snippet you created will be used instead of the one in the XML package (specified in the default key bindings). Refer to the long-tag snippet in the XML package and to the sublime text 2 snippet documentation if you want to see the difference. Refer to the default key bindings to see the overall format for the user key bindings file, if needed.

1 Like