Sublime Forum

Is there a way to specify cursor focus in sublime snippet?

#1

Ok, here is my example:

I have few keyboard shortcuts I created like:

{ “keys”: “ctrl+alt+shift+s”], “command”: “save_all” },
{ “keys”: “ctrl+shift+m”], “command”: “insert_snippet”, “args”: {“name”: “Packages/User/phptag.sublime-snippet” } },
{ “keys”: “ctrl+shift+o”], “command”: “insert_snippet”, “args”: {“name”: “Packages/User/opening_html_tag.sublime-snippet” } },
{ “keys”: “ctrl+shift+c”], “command”: “insert_snippet”, “args”: {“name”: “Packages/User/closing_html_tag.sublime-snippet” } }
]

Let’s take the PHP tag shortcut, my snippet looks like this and work fine:

]]>
PHP tag

I would like the cursor to be here when I insert my tags:

<?php **|**; ?>

instead of having it at the end of the line every time like this:

<?php ; ?>**|**

I would do the same thing for my other snippets.
Is it possible to do so?
How could it be possible?

Thank you very much for your help.
Gabriel

0 Likes

#2

$0 sets the position of the cursor when the snippet ends.

0 Likes

#3

Thanks for the reply.

Where should I add the $0 variable to set the cursor position?
Inside the brackets?
0 Being the first position index inside my snippet I guess?

Thank you.

EDIT 1: Never mind, misunderstood the $0 functionality.
I updated my snippet as this: ]]> and it works perfectly fine!
Thank you very much!

0 Likes