Sublime Forum

End of a snippet

#1

Hi,

there’s something I really don’t understand about snippets.
Suppose I wanted to write one that writes a Python’s class attribute like this :

self.attribute = attribute

So, I wrote my snippet :

<snippet>
    <content><![CDATA[self.${1:property} = $1]]></content>
</snippet>

Now, when I run it, all is fine but once I write “whatever”
like this (| is the cursor pos) :

self.whatever| = whatever

and I hit the tab key, I’ve got this :

self.whatever    | = whatever

I expected :

self.whatever = whatever|

So how could I set the cursor pos at the end of the snippet ?
I’ve also tried

<snippet>
    <content><![CDATA[self.${1:property} = $1$0]]></content>
</snippet>

because it was TextMate behaviour, but it fails.

Thanks for any hint.

0 Likes

#2

Thanks for the lesson sublimator :

  • you fixed my problem ;

  • I was not aware that the keybindings were sequential ; that’s somewhat annoying, but maye we could write a macro for deleting the current word under the cursor.

Other points :

  • With <snippet> <content><![CDATA[self.${1:property} = $1 $2]]></content> </snippet> once expanded, hitting tab brings me to self.property = |, I was expecting self.property = property| because $1 is supposed to be a mirror no ?!

  • Why can’t we set the shortcut inside the snippet defintion ? We have to edit 2 files just for one snippet (a keymap and a snippet).

0 Likes

#3

EDIT: ah I understand you now, yeah the mirroring is buggy/not working

Yes, that’s the problem.

e has a nice a nice GUI for such things. I’ll give your EditPreferences plugin a try, thanks for pointing it to me.

In fact I’ve made a snippets engine a long time ago in Python (for the PyK! http://kib2.free.fr/PyK/ project),
and I’m now a little confused about the way Sublime handles snippets.

0 Likes