Home Download Buy Blog Forum Support

Insert snippet / long-tag issue

Insert snippet / long-tag issue

Postby jcontonio on Wed Jan 23, 2013 5:19 pm

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?
jcontonio
 
Posts: 8
Joined: Wed May 30, 2012 11:40 pm

Re: Insert snippet / long-tag issue

Postby C0D312 on Wed Jan 23, 2013 7:39 pm

That behavior is caused by a tab field somewhere. You can cancel the field by pressing escape.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Insert snippet / long-tag issue

Postby wam on Mon Apr 15, 2013 5:18 am

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:

Code: Select all
<snippet>
    <content><![CDATA[<${1:p}>$0$SELECTION</${1/([^ ]+).*/$1/}>]]></content>
    <tabTrigger>&lt;</tabTrigger>
    <scope>text.xml</scope>
    <description>Long Tag</description>
</snippet>


3. 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).

4. In the User Key Bindings, add:

Code: Select all
{ "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.
wam
 
Posts: 1
Joined: Mon Apr 15, 2013 4:43 am


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 18 guests