How do you add focus points to Atom snippets?


#1

The documentation for snippets talks about focus points, but doesn’t say how to create them.

Many snippets have multiple focus points that you can move through with the Tab key as well

I’m curious if anyone knows how to set a default cursor position within a snippet, so your cursor goes to a certain place after rendering the snippet?


#2

You can use $1, $2, etc in your snippets. For example, the following snippet has 4 focus points, and the first 2 have default values (the stuff between the colon : and closing brace }. Also, as far as I know, the focus point don’t have to be in order, so $2 can come before $1, if you need it to.

  'Function':
    'prefix': 'func'
    'body': "${1:public }function ${2:function_name}($3) \n{$4}"

#3

This is also explained in the Atom Flight Manual section on snippets:

http://flight-manual.atom.io/using-atom/sections/snippets/


#4

I don’t know if there is a limit, but you can definitely have more than two with default values.


#5

Thanks for this, would have been useful info in the documentation.

Already saving me loads of time, though. Cheers!


#6

The documentation mentions focus points at the beginning and then shows some code with focus points further down, but I didn’t make the connection that that’s what they were.

Probably could make it a bit clearer by showing a syntax example where focus points are first introduced.


#7

If you have ideas on how it can be made clearer, there is an Edit button on every page that allows you to easily submit a change request with your suggestions.